@rango-dev/provider-coin98 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-coin98.cjs.development.js +580 -0
- package/dist/provider-coin98.cjs.development.js.map +1 -0
- package/dist/provider-coin98.cjs.production.min.js +2 -0
- package/dist/provider-coin98.cjs.production.min.js.map +1 -0
- package/dist/provider-coin98.esm.js +567 -0
- package/dist/provider-coin98.esm.js.map +1 -0
- package/dist/signer.d.ts +2 -0
- package/package.json +56 -0
- package/src/helpers.ts +28 -0
- package/src/index.ts +113 -0
- package/src/signer.ts +51 -0
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Network } from '@rango-dev/wallets-shared';
|
|
2
|
+
|
|
3
|
+
export function coin98() {
|
|
4
|
+
const { coin98, ethereum } = window;
|
|
5
|
+
|
|
6
|
+
if (!coin98) return null;
|
|
7
|
+
|
|
8
|
+
const instances = new Map();
|
|
9
|
+
|
|
10
|
+
// When disabled overring metamask
|
|
11
|
+
if (coin98.provider) instances.set(Network.ETHEREUM, coin98.provider);
|
|
12
|
+
if (ethereum && ethereum.isCoin98) instances.set(Network.ETHEREUM, ethereum);
|
|
13
|
+
if (coin98.sol) instances.set(Network.SOLANA, coin98.sol);
|
|
14
|
+
|
|
15
|
+
return instances;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
This is how coin98 is getting solana accounts.
|
|
20
|
+
That's the reason we haven't moved it to `shared`
|
|
21
|
+
*/
|
|
22
|
+
export async function getSolanaAccounts(instance: any) {
|
|
23
|
+
await instance.enable();
|
|
24
|
+
const accounts = await instance.request({ method: 'sol_accounts' });
|
|
25
|
+
return {
|
|
26
|
+
accounts,
|
|
27
|
+
};
|
|
28
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getBlockChainNameFromId,
|
|
3
|
+
Network,
|
|
4
|
+
WalletType,
|
|
5
|
+
canSwitchNetworkToEvm,
|
|
6
|
+
chooseInstance,
|
|
7
|
+
getEvmAccounts,
|
|
8
|
+
switchNetworkForEvm,
|
|
9
|
+
CanSwitchNetwork,
|
|
10
|
+
Connect,
|
|
11
|
+
Subscribe,
|
|
12
|
+
SwitchNetwork,
|
|
13
|
+
WalletSigners,
|
|
14
|
+
BlockchainMeta,
|
|
15
|
+
WalletInfo,
|
|
16
|
+
evmBlockchains,
|
|
17
|
+
solanaBlockchain,
|
|
18
|
+
} from '@rango-dev/wallets-shared';
|
|
19
|
+
import { coin98 as coin98_instances } from './helpers';
|
|
20
|
+
import { getSolanaAccounts } from './helpers';
|
|
21
|
+
import signer from './signer';
|
|
22
|
+
|
|
23
|
+
const WALLET = WalletType.COIN98;
|
|
24
|
+
|
|
25
|
+
export const config = {
|
|
26
|
+
type: WALLET,
|
|
27
|
+
// TODO: Get from evm networks
|
|
28
|
+
defaultNetwork: Network.ETHEREUM,
|
|
29
|
+
};
|
|
30
|
+
export const getInstance = coin98_instances;
|
|
31
|
+
|
|
32
|
+
export const connect: Connect = async ({ instance, meta }) => {
|
|
33
|
+
const evm_instance = chooseInstance(instance, meta, Network.ETHEREUM);
|
|
34
|
+
const sol_instance = chooseInstance(instance, meta, Network.SOLANA);
|
|
35
|
+
const evm = await getEvmAccounts(evm_instance);
|
|
36
|
+
const { accounts: solanaAccounts } = await getSolanaAccounts(sol_instance);
|
|
37
|
+
|
|
38
|
+
return [
|
|
39
|
+
evm,
|
|
40
|
+
{
|
|
41
|
+
accounts: solanaAccounts,
|
|
42
|
+
chainId: Network.SOLANA,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const subscribe: Subscribe = ({
|
|
48
|
+
instance,
|
|
49
|
+
meta,
|
|
50
|
+
updateChainId,
|
|
51
|
+
connect,
|
|
52
|
+
}) => {
|
|
53
|
+
const eth = chooseInstance(instance, meta, Network.ETHEREUM);
|
|
54
|
+
eth?.on('chainChanged', (chainId: string) => {
|
|
55
|
+
const network = getBlockChainNameFromId(chainId, meta) || Network.Unknown;
|
|
56
|
+
const targetInstance = chooseInstance(instance, meta, network);
|
|
57
|
+
targetInstance
|
|
58
|
+
.request({ method: 'eth_requestAccounts' })
|
|
59
|
+
.then(() => undefined)
|
|
60
|
+
.catch((err: unknown) => {
|
|
61
|
+
console.log({ err });
|
|
62
|
+
});
|
|
63
|
+
/*
|
|
64
|
+
TODO:
|
|
65
|
+
We are calling `connect` here because signer can't detect
|
|
66
|
+
currect network, I guess the bug is in our signer and it
|
|
67
|
+
gets the wrong network by calling a wrong method or something.
|
|
68
|
+
Anyways, this works for now, maybe we can reconsider it in future
|
|
69
|
+
Whenever we refactored the signer code as well.
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
// we need to update `network` first, if not, it will goes through
|
|
73
|
+
// the switching network and will open unneccessary pop ups.
|
|
74
|
+
updateChainId(chainId);
|
|
75
|
+
connect(network);
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const switchNetwork: SwitchNetwork = async (options) => {
|
|
80
|
+
const instance = chooseInstance(
|
|
81
|
+
options.instance,
|
|
82
|
+
options.meta,
|
|
83
|
+
options.network
|
|
84
|
+
);
|
|
85
|
+
return switchNetworkForEvm({
|
|
86
|
+
...options,
|
|
87
|
+
instance,
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const canSwitchNetworkTo: CanSwitchNetwork = canSwitchNetworkToEvm;
|
|
92
|
+
|
|
93
|
+
export const getSigners: (provider: any) => WalletSigners = signer;
|
|
94
|
+
|
|
95
|
+
export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
|
|
96
|
+
allBlockChains
|
|
97
|
+
) => {
|
|
98
|
+
const evms = evmBlockchains(allBlockChains);
|
|
99
|
+
const solana = solanaBlockchain(allBlockChains);
|
|
100
|
+
return {
|
|
101
|
+
name: 'Coin98',
|
|
102
|
+
img: 'https://raw.githubusercontent.com/rango-exchange/rango-types/main/assets/icons/wallets/coin98.svg',
|
|
103
|
+
installLink: {
|
|
104
|
+
CHROME:
|
|
105
|
+
'https://chrome.google.com/webstore/detail/coin98-wallet/aeachknmefphepccionboohckonoeemg',
|
|
106
|
+
BRAVE:
|
|
107
|
+
'https://chrome.google.com/webstore/detail/coin98-wallet/aeachknmefphepccionboohckonoeemg',
|
|
108
|
+
DEFAULT: 'https://coin98.com/wallet',
|
|
109
|
+
},
|
|
110
|
+
color: '#1d1c25',
|
|
111
|
+
supportedChains: [...evms, ...solana],
|
|
112
|
+
};
|
|
113
|
+
};
|
package/src/signer.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SolanaTransaction,
|
|
3
|
+
Network,
|
|
4
|
+
WalletType,
|
|
5
|
+
WalletSigners,
|
|
6
|
+
getNetworkInstance,
|
|
7
|
+
defaultSigners,
|
|
8
|
+
generalSolanaTransactionExecutor,
|
|
9
|
+
SolanaSigner,
|
|
10
|
+
} from '@rango-dev/wallets-shared';
|
|
11
|
+
import { PublicKey, Transaction } from '@solana/web3.js';
|
|
12
|
+
import bs58 from 'bs58';
|
|
13
|
+
|
|
14
|
+
export default function getSigners(provider: any): WalletSigners {
|
|
15
|
+
return {
|
|
16
|
+
...defaultSigners({
|
|
17
|
+
provider,
|
|
18
|
+
walletType: WalletType.COIN98,
|
|
19
|
+
supportEvm: true,
|
|
20
|
+
}),
|
|
21
|
+
|
|
22
|
+
executeSolanaTransaction: async (
|
|
23
|
+
tx: SolanaTransaction,
|
|
24
|
+
requestId: string
|
|
25
|
+
): Promise<string> => {
|
|
26
|
+
const solProvider = getNetworkInstance(provider, Network.SOLANA);
|
|
27
|
+
|
|
28
|
+
const solanaSigner: SolanaSigner = async (
|
|
29
|
+
solanaWeb3Transaction: Transaction
|
|
30
|
+
) => {
|
|
31
|
+
const response: { publicKey: string; signature: string } =
|
|
32
|
+
await solProvider.request({
|
|
33
|
+
method: 'sol_sign',
|
|
34
|
+
params: [solanaWeb3Transaction],
|
|
35
|
+
});
|
|
36
|
+
const publicKey = new PublicKey(response.publicKey);
|
|
37
|
+
const sign = bs58.decode(response.signature);
|
|
38
|
+
|
|
39
|
+
solanaWeb3Transaction.addSignature(publicKey, Buffer.from(sign));
|
|
40
|
+
const raw = solanaWeb3Transaction.serialize();
|
|
41
|
+
return raw;
|
|
42
|
+
};
|
|
43
|
+
const hash = await generalSolanaTransactionExecutor(
|
|
44
|
+
requestId,
|
|
45
|
+
tx,
|
|
46
|
+
solanaSigner
|
|
47
|
+
);
|
|
48
|
+
return hash;
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|