Skip to content

Commit

Permalink
Remove lit
Browse files Browse the repository at this point in the history
  • Loading branch information
arhtudormorar committed Dec 3, 2024
1 parent 5dd812a commit 424cb69
Show file tree
Hide file tree
Showing 7 changed files with 1,792 additions and 1,718 deletions.
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-dapp-core",
"version": "0.0.0-alpha.9",
"version": "0.0.0-alpha.10",
"main": "out/index.js",
"module": "out/index.js",
"types": "out/index.d.ts",
Expand All @@ -19,8 +19,8 @@
"url": "git+https://github.com/multiversx/mx-sdk-dapp-core.git"
},
"scripts": {
"unpublish-verdaccio": "npm unpublish @multiversx/sdk-dapp-core@0.0.0-alpha.10 --registry http://localhost:4873",
"publish-verdaccio": "npm run unpublish-verdaccio && npm run compile && npm publish --registry http://localhost:4873/",
"unpublish-verdaccio": "npm unpublish @multiversx/sdk-dapp-core --force --registry http://localhost:4873",
"publish-verdaccio": "npm run unpublish-verdaccio && npm run compile-next && npm publish --registry http://localhost:4873/",
"compile": "tsc && tsc-alias",
"build-esbuild": "rimraf out && node esbuild.js",
"build": "yarn build-esbuild && yarn compile",
Expand All @@ -43,7 +43,6 @@
"@multiversx/sdk-web-wallet-iframe-provider": "2.0.1",
"@multiversx/sdk-web-wallet-provider": "3.2.1",
"isomorphic-fetch": "3.0.0",
"lit": "3.2.1",
"lodash": "4.17.21",
"protobufjs": "7.3.0",
"socket.io-client": "4.7.5",
Expand All @@ -58,7 +57,7 @@
"immer": "10.x"
},
"optionalDependencies": {
"@multiversx/sdk-dapp-core-ui": "https://github.com/multiversx/mx-sdk-dapp-core-ui#tm/feature/ldeger-ui"
"@multiversx/sdk-dapp-core-ui": "0.0.0"
},
"resolutions": {
"string-width": "4.1.0"
Expand Down
25 changes: 8 additions & 17 deletions src/core/providers/ProviderFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { setAccountProvider } from './accountProvider';
import { DappProvider } from './DappProvider/DappProvider';
import { createCrossWindowProvider } from './helpers/crossWindow/createCrossWindowProvider';
import { createExtensionProvider } from './helpers/extension/createExtensionProvider';
import { getConfig } from './helpers/getConfig';
import { createIframeProvider } from './helpers/iframe/createIframeProvider';
import { createLedgerProvider } from './helpers/ledger/createLedgerProvider';
import {
Expand All @@ -18,21 +19,11 @@ import {
export class ProviderFactory {
public async create({
type,
config = {
ui: {
ledger: {
eventBus: {} as any,
mount: () => {
throw new Error(
'Ledger UI not implemented. See @multiversx/sdk-dapp-core-ui for more information'
);
}
}
}
},
config: userConfig,
customProvider
}: IProviderFactory): Promise<DappProvider> {
let createdProvider: IProvider | null = null;
const { account, ui } = await getConfig(userConfig);

switch (type) {
case ProviderTypeEnum.extension: {
Expand All @@ -46,7 +37,7 @@ export class ProviderFactory {

case ProviderTypeEnum.crossWindow: {
const provider = await createCrossWindowProvider({
address: config?.account?.address
address: account?.address
});
createdProvider = provider as unknown as IProvider;

Expand All @@ -57,8 +48,8 @@ export class ProviderFactory {

case ProviderTypeEnum.ledger: {
const ledgerProvider = await createLedgerProvider(
config.ui?.ledger.eventBus,
config.ui?.ledger.mount
ui.ledger.eventBus,
ui.ledger.mount
);

if (!ledgerProvider) {
Expand All @@ -83,7 +74,7 @@ export class ProviderFactory {

case ProviderTypeEnum.metamask: {
const provider = await createIframeProvider({
address: config?.account?.address,
address: account?.address,
type: IframeLoginTypes.metamask
});

Expand All @@ -100,7 +91,7 @@ export class ProviderFactory {

case ProviderTypeEnum.passkey: {
const provider = await createIframeProvider({
address: config?.account?.address,
address: account?.address,
type: IframeLoginTypes.passkey
});

Expand Down
35 changes: 35 additions & 0 deletions src/core/providers/helpers/getConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { LedgerConnectModal } from '@multiversx/sdk-dapp-core-ui/dist/components/ledger-connect-modal';
import { defineCustomElements } from '@multiversx/sdk-dapp-core-ui/loader';
import {
IProviderConfig,
ProviderTypeEnum
} from '../types/providerFactory.types';

export const getConfig = async (config: IProviderConfig = {}) => {
console.log('\x1b[42m%s\x1b[0m', 'start');

defineCustomElements(window);
const ledgerModalElement = document.createElement(
'ledger-connect-modal'
) as LedgerConnectModal;
document.body.appendChild(ledgerModalElement);
await customElements.whenDefined('ledger-connect-modal');
const eventBus = await ledgerModalElement.getEventBus();

const ui = {
[ProviderTypeEnum.ledger]: {
eventBus,
mount: () => {
document.body.appendChild(ledgerModalElement);
}
}
};

return {
...config,
ui: {
...ui,
...config.ui
}
};
};
4 changes: 2 additions & 2 deletions src/core/providers/helpers/ledger/createLedgerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { ILedgerAccount } from './ledger.types';
const failInitializeErrorText = 'Check if the MultiversX App is open on Ledger';

export async function createLedgerProvider(
eventBus?: IEventBus,
mount?: () => void
eventBus: IEventBus,
mount: () => void
): Promise<IProvider | null> {
if (!eventBus) {
throw new Error('Event bus not provided for Ledger provider');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isString } from 'lodash';
import isString from 'lodash/isString';

export const secondsToTimeString = (seconds: number) => {
if (seconds <= 0 || isNaN(seconds) || !seconds || isString(seconds)) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/providers/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function getProviderType<TProvider extends object>(
): ProviderTypeEnum {
switch (provider?.constructor) {
case WalletProvider:
return ProviderTypeEnum.webhook;
return ProviderTypeEnum.webhook; // TODO: remove?
case WalletConnectV2Provider:
return ProviderTypeEnum.walletConnect;
case HWProvider:
Expand Down
Loading

0 comments on commit 424cb69

Please sign in to comment.