@rango-dev/provider-okx 0.1.11-next.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers.d.ts +4 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +8 -0
- package/dist/provider-okx.cjs.development.js +533 -0
- package/dist/provider-okx.cjs.development.js.map +1 -0
- package/dist/provider-okx.cjs.production.min.js +2 -0
- package/dist/provider-okx.cjs.production.min.js.map +1 -0
- package/dist/provider-okx.esm.js +522 -0
- package/dist/provider-okx.esm.js.map +1 -0
- package/dist/signer.d.ts +2 -0
- package/package.json +54 -0
- package/src/helpers.ts +50 -0
- package/src/index.ts +98 -0
- package/src/signer.ts +14 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Network,
|
|
3
|
+
WalletType,
|
|
4
|
+
CanSwitchNetwork,
|
|
5
|
+
Connect,
|
|
6
|
+
ProviderConnectResult,
|
|
7
|
+
Subscribe,
|
|
8
|
+
SwitchNetwork,
|
|
9
|
+
WalletSigners,
|
|
10
|
+
canSwitchNetworkToEvm,
|
|
11
|
+
chooseInstance,
|
|
12
|
+
getEvmAccounts,
|
|
13
|
+
switchNetworkForEvm,
|
|
14
|
+
isEvmBlockchain,
|
|
15
|
+
BlockchainMeta,
|
|
16
|
+
WalletInfo,
|
|
17
|
+
} from '@rango-dev/wallets-shared';
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
getSolanaAccounts,
|
|
21
|
+
okx_instance,
|
|
22
|
+
OKX_WALLET_SUPPORTED_CHAINS,
|
|
23
|
+
} from './helpers';
|
|
24
|
+
import signer from './signer';
|
|
25
|
+
|
|
26
|
+
const WALLET = WalletType.OKX;
|
|
27
|
+
|
|
28
|
+
export const config = {
|
|
29
|
+
type: WALLET,
|
|
30
|
+
defaultNetwork: Network.ETHEREUM,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const getInstance = okx_instance;
|
|
34
|
+
export const connect: Connect = async ({ instance, meta }) => {
|
|
35
|
+
let results: ProviderConnectResult[] = [];
|
|
36
|
+
|
|
37
|
+
const evm_instance = chooseInstance(instance, meta, Network.ETHEREUM);
|
|
38
|
+
|
|
39
|
+
if (evm_instance) {
|
|
40
|
+
const evm = await getEvmAccounts(evm_instance);
|
|
41
|
+
results.push(evm);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const solanaResults = await getSolanaAccounts(instance);
|
|
45
|
+
|
|
46
|
+
results = [...results, ...solanaResults];
|
|
47
|
+
|
|
48
|
+
return results;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const subscribe: Subscribe = ({ instance, updateAccounts, meta }) => {
|
|
52
|
+
const ethInstance = chooseInstance(instance, meta, Network.ETHEREUM);
|
|
53
|
+
|
|
54
|
+
ethInstance?.on('accountsChanged', async (addresses: string[]) => {
|
|
55
|
+
const eth_chainId = meta
|
|
56
|
+
.filter(isEvmBlockchain)
|
|
57
|
+
.find((blockchain) => blockchain.name === Network.ETHEREUM)?.chainId;
|
|
58
|
+
|
|
59
|
+
updateAccounts(addresses, eth_chainId);
|
|
60
|
+
const [{ accounts, chainId }] = await getSolanaAccounts(instance);
|
|
61
|
+
updateAccounts(accounts, chainId);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const switchNetwork: SwitchNetwork = async (options) => {
|
|
66
|
+
const instance = chooseInstance(
|
|
67
|
+
options.instance,
|
|
68
|
+
options.meta,
|
|
69
|
+
options.network
|
|
70
|
+
);
|
|
71
|
+
return switchNetworkForEvm({
|
|
72
|
+
...options,
|
|
73
|
+
instance,
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const canSwitchNetworkTo: CanSwitchNetwork = canSwitchNetworkToEvm;
|
|
78
|
+
|
|
79
|
+
export const getSigners: (provider: any) => WalletSigners = signer;
|
|
80
|
+
|
|
81
|
+
export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
|
|
82
|
+
allBlockChains
|
|
83
|
+
) => ({
|
|
84
|
+
name: 'OKX',
|
|
85
|
+
img: 'https://raw.githubusercontent.com/rango-exchange/rango-types/main/assets/icons/wallets/okx.png',
|
|
86
|
+
installLink: {
|
|
87
|
+
CHROME:
|
|
88
|
+
'https://chrome.google.com/webstore/detail/okx-wallet/mcohilncbfahbmgdjkbpemcciiolgcge',
|
|
89
|
+
BRAVE:
|
|
90
|
+
'https://chrome.google.com/webstore/detail/okx-wallet/mcohilncbfahbmgdjkbpemcciiolgcge',
|
|
91
|
+
FIREFOX: 'https://addons.mozilla.org/en-US/firefox/addon/okexwallet',
|
|
92
|
+
DEFAULT: 'https://www.okx.com/web3',
|
|
93
|
+
},
|
|
94
|
+
color: 'white',
|
|
95
|
+
supportedChains: allBlockChains.filter((blockchainMeta) =>
|
|
96
|
+
OKX_WALLET_SUPPORTED_CHAINS.includes(blockchainMeta.name as Network)
|
|
97
|
+
),
|
|
98
|
+
});
|
package/src/signer.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WalletType,
|
|
3
|
+
WalletSigners,
|
|
4
|
+
defaultSigners,
|
|
5
|
+
} from '@rango-dev/wallets-shared';
|
|
6
|
+
|
|
7
|
+
export default function getSigners(provider: any): WalletSigners {
|
|
8
|
+
return defaultSigners({
|
|
9
|
+
provider,
|
|
10
|
+
walletType: WalletType.OKX,
|
|
11
|
+
supportEvm: true,
|
|
12
|
+
supportSolana: true,
|
|
13
|
+
});
|
|
14
|
+
}
|