From c39cd871dd2f51bf28b64b440c685f203eb1871b Mon Sep 17 00:00:00 2001 From: Sebastien Guillemot Date: Fri, 1 Dec 2023 02:51:01 +0900 Subject: [PATCH] Misc fixes for EVM wallet connection (#260) --- .../paima-sdk/paima-mw-core/src/endpoints/internal.ts | 3 +++ .../paima-sdk/paima-mw-core/src/wallets/evm/injected.ts | 8 +++++--- .../paima-sdk/paima-mw-core/src/wallets/wallet-modes.ts | 5 ++++- packages/paima-sdk/paima-providers/src/evm/injected.ts | 6 +++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/paima-sdk/paima-mw-core/src/endpoints/internal.ts b/packages/paima-sdk/paima-mw-core/src/endpoints/internal.ts index 6a7fa4b3f..868ac55a1 100644 --- a/packages/paima-sdk/paima-mw-core/src/endpoints/internal.ts +++ b/packages/paima-sdk/paima-mw-core/src/endpoints/internal.ts @@ -13,6 +13,9 @@ import { TruffleConnector } from '@paima/providers'; import HDWalletProvider from '@truffle/hdwallet-provider'; import type { LoginInfo } from '../wallets/wallet-modes.js'; +/** + * @deprecated use specificWalletLogin instead + */ export async function userWalletLoginWithoutChecks( loginInfo: LoginInfo, setDefault: boolean = true diff --git a/packages/paima-sdk/paima-mw-core/src/wallets/evm/injected.ts b/packages/paima-sdk/paima-mw-core/src/wallets/evm/injected.ts index 5d4c72f6f..7baa5df7c 100644 --- a/packages/paima-sdk/paima-mw-core/src/wallets/evm/injected.ts +++ b/packages/paima-sdk/paima-mw-core/src/wallets/evm/injected.ts @@ -117,9 +117,11 @@ export async function evmLoginWrapper( // If the fee has increased beyond the default value, posting won't work. } try { - if (!(await verifyWalletChain())) { - if (!(await switchChain())) { - return errorFxn(PaimaMiddlewareErrorCode.EVM_CHAIN_SWITCH); + if (loginInfo.checkChainId !== false) { + if (!(await verifyWalletChain())) { + if (!(await switchChain())) { + return errorFxn(PaimaMiddlewareErrorCode.EVM_CHAIN_SWITCH); + } } } } catch (err) { diff --git a/packages/paima-sdk/paima-mw-core/src/wallets/wallet-modes.ts b/packages/paima-sdk/paima-mw-core/src/wallets/wallet-modes.ts index f39dd73c6..abddd18c0 100644 --- a/packages/paima-sdk/paima-mw-core/src/wallets/wallet-modes.ts +++ b/packages/paima-sdk/paima-mw-core/src/wallets/wallet-modes.ts @@ -21,7 +21,10 @@ export type BaseLoginInfo = { preference?: InjectionPreference; }; export type LoginInfoMap = { - [WalletMode.EvmInjected]: BaseLoginInfo & { preferBatchedMode: boolean }; + [WalletMode.EvmInjected]: BaseLoginInfo & { + preferBatchedMode: boolean; + checkChainId?: boolean; + }; [WalletMode.EvmEthers]: { connection: ActiveConnection; preferBatchedMode: boolean }; [WalletMode.Cardano]: BaseLoginInfo; [WalletMode.Polkadot]: BaseLoginInfo; diff --git a/packages/paima-sdk/paima-providers/src/evm/injected.ts b/packages/paima-sdk/paima-providers/src/evm/injected.ts index 386109c31..1d0898c3a 100644 --- a/packages/paima-sdk/paima-providers/src/evm/injected.ts +++ b/packages/paima-sdk/paima-providers/src/evm/injected.ts @@ -132,7 +132,7 @@ export class EvmInjectedConnector implements IConnector { allWallets.push({ metadata: { name: 'metamask', - displayName: 'Metamask', + displayName: 'MetaMask', }, api: () => Promise.resolve(ethereum), }); @@ -153,11 +153,15 @@ export class EvmInjectedConnector implements IConnector { static getWalletOptions(): ConnectionOption[] { const withDuplicates = EvmInjectedConnector.getPossiblyDuplicateWalletOptions(); const seenNames: Set = new Set(); + const seenDisplayNames: Set = new Set(); const result: ConnectionOption[] = []; for (const option of withDuplicates) { + const lowerCaseName = option.metadata.displayName.toLowerCase(); if (seenNames.has(option.metadata.name)) continue; + if (seenDisplayNames.has(lowerCaseName)) continue; seenNames.add(option.metadata.name); + seenDisplayNames.add(lowerCaseName); result.push(option); }