Skip to content

Commit

Permalink
Merge branch 'development' into tm/integrate-walletconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
arhtudormorar committed Nov 6, 2024
2 parents 346e061 + 512e91a commit 56e0f33
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 55 deletions.
7 changes: 1 addition & 6 deletions src/core/methods/signMessage/verifyMessage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
Address,
Message,
MessageComputer,
SignableMessage
} from '@multiversx/sdk-core/out';
import { Address, Message, MessageComputer } from '@multiversx/sdk-core/out';
import { getVerifier } from './getVerifier';

export function verifyMessage(signedMessage: string) {
Expand Down
59 changes: 39 additions & 20 deletions src/core/providers/ProviderFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {
import { createLedgerProvider } from './helpers/ledger/createLedgerProvider';
import { createCrossWindowProvider } from './helpers/crossWindow/createCrossWindowProvider';
import { createExtensionProvider } from './helpers/extension/createExtensionProvider';
import { createMetamaskProvider } from './helpers/iframe/createMetamaskProvider';
import { createWalletconnectProvider } from './helpers/walletconnect/createWalletconnectProvider';
import { createIframeProvider } from './helpers/iframe/createIframeProvider';
import { IframeLoginTypes } from '@multiversx/sdk-web-wallet-iframe-provider/out/constants';
import { networkSelector } from 'store/selectors';
import { getState } from 'store/store';
import { createWalletconnectProvider } from './helpers/walletconnect/createWalletconnectProvider';

export class ProviderFactory {
public async create({
Expand All @@ -18,30 +19,31 @@ export class ProviderFactory {
customProvider
}: IProviderFactory): Promise<IProvider | undefined> {
let createdProvider: IProvider | undefined;
const network = networkSelector(getState());
const network = {
...networkSelector(getState()),
...config.network
};
const { metamaskSnapWalletAddress = '', walletAddress } = network;
const address = config.account?.address;

switch (type) {
case ProviderTypeEnum.extension: {
const provider = await createExtensionProvider();
createdProvider = provider as unknown as IProvider;

createdProvider.getType = () => {
return ProviderTypeEnum.extension;
};
createdProvider.getType = () => ProviderTypeEnum.extension;

break;
}

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

createdProvider.getType = () => {
return ProviderTypeEnum.crossWindow;
};
createdProvider.getType = () => ProviderTypeEnum.crossWindow;

break;
}
Expand All @@ -55,12 +57,34 @@ export class ProviderFactory {

createdProvider = ledgerProvider;

createdProvider.getType = () => ProviderTypeEnum.ledger;

break;
}

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

if (!provider) {
return;
}

createdProvider = provider as unknown as IProvider;

createdProvider.getType = () => ProviderTypeEnum.metamask;

break;
}

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

if (!provider) {
Expand All @@ -69,19 +93,14 @@ export class ProviderFactory {

createdProvider = provider as unknown as IProvider;

createdProvider.getType = () => {
return ProviderTypeEnum.metamask;
};
createdProvider.getType = () => ProviderTypeEnum.passkey;

break;
}

case ProviderTypeEnum.walletconnect: {
createdProvider = createWalletconnectProvider({
network: {
...network,
...config.network
}
network
});
break;
}
Expand Down
25 changes: 25 additions & 0 deletions src/core/providers/helpers/iframe/createIframeProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { IframeProvider } from '@multiversx/sdk-web-wallet-iframe-provider/out';
import { IframeLoginTypes } from '@multiversx/sdk-web-wallet-iframe-provider/out/constants';

interface ICreateIframeProviderProps {
address?: string;
metamaskSnapWalletAddress: string;
type: IframeLoginTypes.metamask | IframeLoginTypes.passkey;
}

export async function createIframeProvider({
metamaskSnapWalletAddress,
address = '',
type
}: ICreateIframeProviderProps) {
const provider = IframeProvider.getInstance();
provider.setLoginType(type);
provider.setWalletUrl(metamaskSnapWalletAddress);

if (address) {
provider.setAccount({ address });
}

await provider.init();
return provider;
}
28 changes: 0 additions & 28 deletions src/core/providers/helpers/iframe/createMetamaskProvider.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/core/providers/types/providerFactory.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface IProvider extends IDAppProviderBase {
}

export interface IProviderConfig {
network: CustomNetworkType;
network?: CustomNetworkType;
account?: {
address: string;
};
Expand All @@ -34,6 +34,7 @@ export enum ProviderTypeEnum {
ledger = 'ledger',
opera = 'opera',
metamask = 'metamask',
passkey = 'passkey',
webhook = 'webhook',
custom = 'custom',
none = ''
Expand Down
1 change: 1 addition & 0 deletions src/types/network.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface CustomNetworkType {
walletConnectDeepLink?: string;
walletConnectBridgeAddresses?: string[];
walletAddress?: string;
metamaskSnapWalletAddress?: string;
apiAddress?: string;
explorerAddress?: string;
skipFetchFromServer?: boolean;
Expand Down

0 comments on commit 56e0f33

Please sign in to comment.