Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tm/feature/ledger UI external #36

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 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 @@ -57,6 +56,9 @@
"bignumber.js": "9.x",
"immer": "10.x"
},
"optionalDependencies": {
"@multiversx/sdk-dapp-core-ui": "0.0.0"
},
"resolutions": {
"string-width": "4.1.0"
},
Expand Down
1 change: 1 addition & 0 deletions src/core/methods/account/getWebviewToken.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getWindowLocation } from 'utils/window/getWindowLocation';

// TODO: also get from store
export function getWebviewToken() {
const { search } = getWindowLocation();
const urlSearchParams = new URLSearchParams(search) as any;
Expand Down
15 changes: 10 additions & 5 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,10 +19,11 @@ import {
export class ProviderFactory {
public async create({
type,
config,
config: userConfig,
customProvider
}: IProviderFactory): Promise<DappProvider> {
let createdProvider: IProvider | null = null;
const { account, ui } = await getConfig(userConfig);

switch (type) {
case ProviderTypeEnum.extension: {
Expand All @@ -35,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 @@ -45,7 +47,10 @@ export class ProviderFactory {
}

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

if (!ledgerProvider) {
throw new Error('Unable to create ledger provider');
Expand All @@ -69,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 @@ -86,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
}
};
};
36 changes: 0 additions & 36 deletions src/core/providers/helpers/ledger/components/EventBus.ts

This file was deleted.

This file was deleted.

Loading
Loading