Skip to content

Commit

Permalink
Misc fixes for EVM wallet connection (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt authored Nov 30, 2023
1 parent 190733e commit c39cd87
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/paima-sdk/paima-mw-core/src/endpoints/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions packages/paima-sdk/paima-mw-core/src/wallets/evm/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion packages/paima-sdk/paima-mw-core/src/wallets/wallet-modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ export type BaseLoginInfo<Api> = {
preference?: InjectionPreference<Api>;
};
export type LoginInfoMap = {
[WalletMode.EvmInjected]: BaseLoginInfo<EvmApi> & { preferBatchedMode: boolean };
[WalletMode.EvmInjected]: BaseLoginInfo<EvmApi> & {
preferBatchedMode: boolean;
checkChainId?: boolean;
};
[WalletMode.EvmEthers]: { connection: ActiveConnection<EthersApi>; preferBatchedMode: boolean };
[WalletMode.Cardano]: BaseLoginInfo<CardanoApi>;
[WalletMode.Polkadot]: BaseLoginInfo<PolkadotApi>;
Expand Down
6 changes: 5 additions & 1 deletion packages/paima-sdk/paima-providers/src/evm/injected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class EvmInjectedConnector implements IConnector<EvmApi> {
allWallets.push({
metadata: {
name: 'metamask',
displayName: 'Metamask',
displayName: 'MetaMask',
},
api: () => Promise.resolve(ethereum),
});
Expand All @@ -153,11 +153,15 @@ export class EvmInjectedConnector implements IConnector<EvmApi> {
static getWalletOptions(): ConnectionOption<EvmApi>[] {
const withDuplicates = EvmInjectedConnector.getPossiblyDuplicateWalletOptions();
const seenNames: Set<string> = new Set();
const seenDisplayNames: Set<string> = new Set();

const result: ConnectionOption<EvmApi>[] = [];
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);
}

Expand Down

0 comments on commit c39cd87

Please sign in to comment.