Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OKX wallet #312

Merged
merged 2 commits into from
Feb 22, 2024
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
Binary file added public/wallets/okx-wallet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/constants/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
KeplrIcon,
MathWalletIcon,
MetaMaskIcon,
OkxWalletIcon,
RainbowIcon,
TokenPocketIcon,
TrustWalletIcon,
Expand Down Expand Up @@ -89,6 +90,7 @@ export enum WalletType {
// Ledger = 'LEDGER',
MathWallet = 'MATH_WALLET',
MetaMask = 'METAMASK',
OkxWallet = 'OKX_WALLET',
Rainbow = 'RAINBOW_WALLET',
TokenPocket = 'TOKEN_POCKET',
TrustWallet = 'TRUST_WALLET',
Expand All @@ -102,6 +104,7 @@ const WALLET_CONNECT_EXPLORER_RECOMMENDED_WALLETS = {
imToken: 'ef333840daf915aafdc4a004525502d6d49d77bd9c65e0642dbaefb3c2893bef',
TokenPocket: '20459438007b75f4f4acb98bf29aa3b800550309646d375da5fd4aac6c2a2c66',
Trust: '4622a2b2d6af1c9844944291e5e7351a6aa24cd7b23099efac1b2fd875da31a0',
OkxWallet: '971e689d0a5be527bac79629b4ee9b925e82208e5168b733496a09c0faed0709',
Rainbow: '1ae92b26df02f0abca6304df07debccd18262fdf5fe82daa81593582dac9a369',
Zerion: 'ecc4036f814562b41a5268adc86270fba1365471402006302e70169465b7ac18',
Ledger: '19177a98252e07ddfc9af2083ba8e07ef627cb6103467ffebb3f8f4205fd7927',
Expand Down Expand Up @@ -212,6 +215,14 @@ export const wallets: Record<WalletType, WalletConfig> = {
matchesInjectedEip1193: isMetaMask,
walletconnect2Id: WALLET_CONNECT_EXPLORER_RECOMMENDED_WALLETS.Metamask,
},
[WalletType.OkxWallet]: {
type: WalletType.OkxWallet,
stringKey: STRING_KEYS.OKX_WALLET,
icon: OkxWalletIcon,
connectionTypes: [WalletConnectionType.InjectedEip1193, WalletConnectionType.WalletConnect2],
matchesInjectedEip1193: (provider) => provider.isOkxWallet,
walletconnect2Id: WALLET_CONNECT_EXPLORER_RECOMMENDED_WALLETS.OkxWallet,
},
[WalletType.Rainbow]: {
type: WalletType.Rainbow,
stringKey: STRING_KEYS.RAINBOW_WALLET,
Expand Down Expand Up @@ -278,6 +289,10 @@ export type WithInjectedWeb3Provider = {
};
};

export type WithInjectedOkxWalletProvider = {
okxwallet: InjectedWeb3Provider;
};

// Wallet connections

export type WalletConnection = {
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useDisplayedWallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ export const useDisplayedWallets = () => {
isDev && WalletType.Keplr,

WalletType.WalletConnect2,

WalletType.CoinbaseWallet,


WalletType.OkxWallet,
// Hide these wallet options until they can be properly tested on mainnet
// WalletType.ImToken,
// WalletType.Rainbow,
Expand Down
1 change: 1 addition & 0 deletions src/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export { default as LedgerIcon } from './wallets/ledger.svg';
export { default as MagicIcon } from './wallets/magic.svg';
export { default as MathWalletIcon } from './wallets/mathwallet.svg';
export { default as MetaMaskIcon } from './wallets/metamask.svg';
export { default as OkxWalletIcon } from './wallets/okx-wallet.svg';
export { default as RainbowIcon } from './wallets/rainbow-wallet.svg';
export { default as TestWalletIcon } from './wallets/test-wallet.svg';
export { default as TokenPocketIcon } from './wallets/tokenpocket.svg';
Expand Down
1 change: 1 addition & 0 deletions src/icons/wallets/okx-wallet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 7 additions & 10 deletions src/lib/wallet/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type InjectedCoinbaseWalletExtensionProvider,
type WithInjectedEthereumProvider,
type WithInjectedWeb3Provider,
type WithInjectedOkxWalletProvider,
} from '@/constants/wallets';

import { isTruthy } from '../isTruthy';
Expand All @@ -18,15 +19,6 @@ export const isMetaMask = (provider: ExternalProvider) => (
&& (
!(provider as InjectedCoinbaseWalletExtensionProvider).overrideIsMetaMask
)

/* not a MetaMask wannabe! */
&& (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this because some wallets such as OKX wallet purposely override the metamask ethereum provider and this check prevents the override and would skip the provider altogether. This will then fallback to WalletConnect.

I think we should not do this as it should not be the dApp's call on how the user choose to manage there wallet extension defaults/overrides. If the user wants to override their metamask with another wallet, we should let them.

Reflect.ownKeys(provider).filter((key) =>
typeof key === 'string'
&& key.match(/^is/)
&& !['isConnected', 'isMetaMask'].includes(key)
).length === 0
)
)

/*
Expand Down Expand Up @@ -54,5 +46,10 @@ export const detectInjectedEip1193Providers = (): ExternalProvider[] => {
? ethereumProvider.providers
: [];

return [...displacedProviders, ethereumProvider, web3Provider].filter(isTruthy);
const okxWalletProvider = (globalThis as typeof globalThis & WithInjectedOkxWalletProvider)
?.okxwallet;

return [...displacedProviders, ethereumProvider, web3Provider, okxWalletProvider].filter(
isTruthy
);
};