Skip to content
Merged
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
5 changes: 3 additions & 2 deletions packages/sdk-multichain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@biomejs/biome": "2.0.0",
"@metamask/auto-changelog": "^3.4.3",
"@react-native-async-storage/async-storage": "^1.23.1",
"@types/jsdom": "^21.1.7",
"@types/ws": "^8.18.1",
"@vitest/coverage-v8": "^3.2.4",
"esbuild-plugin-umd-wrapper": "^3.0.0",
Expand All @@ -53,8 +54,8 @@
},
"license": "MIT",
"dependencies": {
"@metamask/mobile-wallet-protocol-core": "^0.1.0",
"@metamask/mobile-wallet-protocol-dapp-client": "^0.1.0",
"@metamask/mobile-wallet-protocol-core": "^0.2.0",
"@metamask/mobile-wallet-protocol-dapp-client": "^0.2.1",
"@metamask/multichain-api-client": "^0.8.0",
"@metamask/onboarding": "^1.0.1",
"@metamask/sdk-analytics": "workspace:^",
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk-multichain/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export const MWP_RELAY_URL = 'wss://mm-sdk-relay.api.cx.metamask.io/connection/websocket';

export const METAMASK_CONNECT_BASE_URL = 'https://metamask.app.link/connect';
export const METAMASK_DEEPLINK_BASE = 'metamask://connect';
476 changes: 192 additions & 284 deletions packages/sdk-multichain/src/connect.test.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/sdk-multichain/src/domain/errors/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ export class RPCReadonlyRequestErr extends BaseErr<'RPC', RPCErrorCodes> {
export class RPCInvokeMethodErr extends BaseErr<'RPC', RPCErrorCodes> {
static readonly code = 53;
constructor(public readonly reason: string) {
super(`RPCErr${RPCInvokeMethodErr.code}: RPC Client invoke method reason ${reason}`, RPCInvokeMethodErr.code);
super(`RPCErr${RPCInvokeMethodErr.code}: RPC Client invoke method reason (${reason})`, RPCInvokeMethodErr.code);
}
}
1 change: 0 additions & 1 deletion packages/sdk-multichain/src/domain/multichain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export abstract class MultichainCore extends EventEmitter<SDKEvents> {
abstract provider: MultichainApiClient<RPCAPI>;
abstract transport: Transport;

abstract getCurrentSession(): Promise<SessionData | undefined>;
/**
* Establishes a connection to the multichain provider, or re-use existing session
*
Expand Down
18 changes: 15 additions & 3 deletions packages/sdk-multichain/src/domain/multichain/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { StoreClient } from '../store';
import type { MultichainCore, SessionData } from '.';
import type { RPC_URLS_MAP } from './api/types';
import type { MultichainCore } from '.';
import type { RPC_URLS_MAP, Scope } from './api/types';
import type { ModalFactory } from '../../ui';
import type { SessionRequest } from '@metamask/mobile-wallet-protocol-core';
import type { PlatformType } from '../platform';
import type { Transport } from '@metamask/multichain-api-client';
import type { CaipAccountId } from '@metamask/utils';

export type { SessionData } from '@metamask/multichain-api-client';

Expand Down Expand Up @@ -56,13 +58,19 @@ export type MultichainOptions = {
preferDesktop?: boolean;
};
mobile?: {
preferredOpenLink?: (deeplink: string, target?: string) => void;
/**
* The `MetaMaskSDK` constructor option `useDeeplink: boolean` controls which type of link is used:
* - If `true`, the SDK will attempt to use the `metamask://` deeplink.
* - If `false` (the default for web), the SDK will use the `https://metamask.app.link` universal link.
*/
Comment thread
chakra-guy marked this conversation as resolved.
useDeeplink?: boolean;
};
/** Optional transport configuration */
transport?: {
/** Extension ID for browser extension transport */
extensionId?: string;
onResumeSession?: (session: SessionData) => void;
onNotification?: (notification: unknown) => void;
};
};

Expand All @@ -79,3 +87,7 @@ type MultiChainFNOptions = Omit<MultichainOptions, 'storage' | 'ui'> & {
* providing all necessary options for SDK initialization.
*/
export type CreateMultichainFN = (options: MultiChainFNOptions) => Promise<MultichainCore>;

export type ExtendedTransport = Omit<Transport, 'connect'> & {
connect: (props?: { scopes: Scope[]; caipAccountIds: CaipAccountId[] }) => Promise<void>;
};
12 changes: 12 additions & 0 deletions packages/sdk-multichain/src/domain/platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,15 @@ export function isMetamaskExtensionInstalled(): boolean {
}
return Boolean(window.ethereum?.isMetaMask);
}

export function isSecure() {
const platformType = getPlatformType();
return isReactNative() || platformType === PlatformType.MobileWeb;
}

export function hasExtension() {
if (typeof window !== 'undefined') {
return window.ethereum?.isMetaMask ?? false;
}
return false;
}
2 changes: 1 addition & 1 deletion packages/sdk-multichain/src/domain/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface InstallWidgetProps extends Components.MmInstallModal {

export interface OTPCodeWidgetProps extends Components.MmOtpModal {
parentElement?: Element;
onClose: () => void;
onClose: () => Promise<void>;
onDisconnect?: () => void;
createOTPCode: () => Promise<OTPCode>;
updateOTPCode: (otpValue: string) => void;
Expand Down
Loading
Loading