-
Notifications
You must be signed in to change notification settings - Fork 3
/
createWallets.ts
89 lines (78 loc) · 2.74 KB
/
createWallets.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {ChainId} from '@layerzerolabs/lz-sdk';
import { toEvmChainId } from '@layerzerolabs/ui-core';
import {Wallet} from '@layerzerolabs/ui-wallet';
import {
CoinbaseWallet,
CoreWallet,
ExternalWallet,
InjectedWallet,
MetaMaskWallet,
PhantomWallet as PhantomWalletEvm,
ProviderIdentityFlag,
WalletConnect,
} from '@layerzerolabs/ui-wallet-evm';
import { isMobile } from '../utils/platform';
type ArrayOneOrMore<T> = {
0: T;
} & Array<T>;
export enum WalletType {
SAFEPAL = 'SafePal',
PHANTOM = 'Phantom',
METAMASK = 'MetaMask',
COINBASE = 'CoinBase',
BRAVE = 'Brave',
CORE = 'Core'
}
// if icon is not available at https://icons-ckg.pages.dev/lz-dark/wallets/<wallet-name-to-lower>.svg
// e.g. https://icons-ckg.pages.dev/lz-dark/wallets/metamask.svg,
// add wallet type to list to use the provided icon url
export const useIconUrl = [WalletType.SAFEPAL as string]
class SafePal extends InjectedWallet {
type = WalletType.SAFEPAL;
identityFlag = ProviderIdentityFlag.SafePal;
readonly url = "https://www.safepal.com/";
readonly icon = "https://pbs.twimg.com/profile_images/1676254262505123840/NhRRmBnl_400x400.png";
}
export class BraveWallet extends ExternalWallet {
type = WalletType.BRAVE;
identityFlag = ProviderIdentityFlag.BraveWallet;
readonly url = "https://brave.com/wallet/";
readonly icon = "https://icons-ckg.pages.dev/lz-light/wallets/brave.svg";
}
enum ChainListId {
TELOS = 40,
POLYGON = 137,
ARBITRUM = 42161,
BNB = 56,
AVALANCHE = 43114
}
export function createWallets(chains: ChainId[]): Record<string, Wallet<unknown>> {
const wallets: Record<string, Wallet<unknown>> = {};
// evm
wallets.metamaskWallet = new MetaMaskWallet();
wallets.coinbaseWallet = new CoinbaseWallet();
wallets.coreWallet = new CoreWallet();
// Brave wallet only supported on mobile at the moment, see https://github.com/telosnetwork/teloscan/issues/544
if (isMobile()){
wallets.braveWallet = new BraveWallet();
}
wallets.phantomEvm = new PhantomWalletEvm();
wallets.safePal = new SafePal();
const evmChains = chains.map(toEvmChainId) as ArrayOneOrMore<number>;
wallets.walletConnect = new WalletConnect({
projectId: process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID as string,
showQrModal: true,
optionalChains: evmChains,
rpcMap: {
[ChainListId.TELOS]: 'https://mainnet.telos.net:443/evm',
[ChainListId.POLYGON]: 'https://polygon-rpc.com/',
[ChainListId.ARBITRUM]: 'https://arb1.arbitrum.io/rpc',
[ChainListId.BNB]: 'https://bsc-dataseed.binance.org/',
[ChainListId.AVALANCHE]: 'https://api.avax.network/ext/bc/C/rpc',
},
});
if (typeof window !== 'undefined') {
Object.values(wallets).forEach((wallet) => wallet.autoConnect());
}
return wallets;
}