Skip to content
This repository was archived by the owner on Jun 29, 2023. It is now read-only.

Commit a6301ce

Browse files
authored
Merge pull request #5 from sei-protocol/feature/dynamic-chain-config
Dynamic chain configs
2 parents 6f1c539 + 7c1c9b5 commit a6301ce

File tree

3 files changed

+93
-98
lines changed

3 files changed

+93
-98
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ A library for Sei written in Typescript.
1313
### Wallet
1414
```import { connect, SUPPORTED_WALLETS } from '@sei-js/core/wallet```
1515

16-
| Property | Type | Description |
17-
|---------------------|---------------------------------------------------|-------------------------------------------------------------------------------|
18-
| connect() | (walletKey: string) => { accounts, offlineSigner} | Async function to connect to input wallet |
19-
| SUPPORTED_WALLETS | string[] | A list of currently supported wallets which can be passed to connect() |
20-
| KEPLR_CHAIN_SUGGEST | object | A pre defined object to be passed to keplrs experimentalChainSuggest function |
16+
| Property | Type | Description |
17+
|-------------------|-----------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
18+
| connect() | (walletKey: string) => { accounts, offlineSigner} | Async function to connect to input wallet |
19+
| SUPPORTED_WALLETS | string[] | A list of currently supported wallets which can be passed to connect() |
20+
| getChainSuggest | (chainId?: string, restUrl?: string, rpcUrl?: string) -> object | A pre defined object to be passed to a wallets experimentalChainSuggest function. Takes optional parameters for chainId, restUrl, and rpcUrl. |
2121

2222
### Client
2323
#### Query Client

src/wallet/config.ts

+84-89
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,94 @@
1-
import { SupportedWallet } from "./types";
1+
import { SupportedWallet } from './types';
22

33
const baseDenomTokenId = `factory/sei1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjqpeheyc/uust2`;
4-
const chainId = 'atlantic-1';
5-
const restUrl = "https://sei-chain-incentivized.com/sei-chain-app"
6-
const rpcUrl = "https://sei-chain-incentivized.com/sei-chain-tm/";
7-
const prefix = "sei";
8-
9-
export const KEPLR_CHAIN_SUGGEST = {
10-
chainId: chainId,
11-
chainName: "Sei Testnet",
12-
rpc: rpcUrl,
13-
rest: restUrl,
14-
bip44: {
15-
coinType: 118,
16-
},
17-
bech32Config: {
18-
bech32PrefixAccAddr: prefix,
19-
bech32PrefixAccPub: `${prefix}pub`,
20-
bech32PrefixValAddr: `${prefix}valoper`,
21-
bech32PrefixValPub: `${prefix}valoperpub`,
22-
bech32PrefixConsAddr: `${prefix}valcons`,
23-
bech32PrefixConsPub: `${prefix}valconspub`,
24-
},
25-
currencies: [
26-
{
27-
coinDenom: "SEI",
28-
coinMinimalDenom: "usei",
29-
coinDecimals: 6,
30-
},
31-
{
32-
coinDenom: "USDC",
33-
coinMinimalDenom: "uusdc",
34-
coinDecimals: 6,
35-
coinGeckoId: "usd-coin",
36-
},
37-
{
38-
coinDenom: "ATOM",
39-
coinMinimalDenom: "uatom",
40-
coinDecimals: 6,
41-
coinGeckoId: "cosmos",
42-
},
43-
{
44-
coinDenom: "WETH",
45-
coinMinimalDenom:
46-
"ibc/C2A89D98873BB55B62CE86700DFACA646EC80352E8D03CC6CF34DD44E46DC75D",
47-
coinDecimals: 18,
48-
coinGeckoId: "weth",
49-
},
50-
{
51-
coinDenom: "WBTC",
52-
coinMinimalDenom:
53-
"ibc/42BCC21A2B784E813F8878739FD32B4AA2D0A68CAD94F4C88B9EA98609AB0CCD",
54-
coinDecimals: 8,
55-
coinGeckoId: "bitcoin",
56-
},
57-
{
58-
coinDenom: "aUSDC",
59-
coinMinimalDenom:
60-
"ibc/6D45A5CD1AADE4B527E459025AC1A5AEF41AE99091EF3069F3FEAACAFCECCD21",
61-
coinDecimals: 6,
62-
coinGeckoId: "usd-coin",
63-
},
64-
{
65-
coinDenom: "UST2",
66-
coinMinimalDenom:
67-
baseDenomTokenId,
68-
coinDecimals: 6,
69-
},
70-
],
71-
feeCurrencies: [
72-
{
73-
coinDenom: "SEI",
74-
coinMinimalDenom: "usei",
75-
coinDecimals: 6,
76-
},
77-
],
78-
stakeCurrency: {
79-
coinDenom: "SEI",
80-
coinMinimalDenom: "usei",
81-
coinDecimals: 6,
82-
},
83-
coinType: 118,
84-
features: ["stargate", "ibc-transfer", "cosmwasm"],
85-
}
4+
const prefix = 'sei';
865

6+
export const getChainSuggest = (
7+
chainId: string = 'atlantic-1',
8+
restUrl: string = 'https://sei-chain-incentivized.com/sei-chain-app',
9+
rpcUrl: string = 'https://sei-chain-incentivized.com/sei-chain-tm/'
10+
) => {
11+
return {
12+
chainId: chainId,
13+
chainName: 'Sei Testnet',
14+
rpc: rpcUrl,
15+
rest: restUrl,
16+
bip44: {
17+
coinType: 118
18+
},
19+
bech32Config: {
20+
bech32PrefixAccAddr: prefix,
21+
bech32PrefixAccPub: `${prefix}pub`,
22+
bech32PrefixValAddr: `${prefix}valoper`,
23+
bech32PrefixValPub: `${prefix}valoperpub`,
24+
bech32PrefixConsAddr: `${prefix}valcons`,
25+
bech32PrefixConsPub: `${prefix}valconspub`
26+
},
27+
currencies: [
28+
{
29+
coinDenom: 'SEI',
30+
coinMinimalDenom: 'usei',
31+
coinDecimals: 6
32+
},
33+
{
34+
coinDenom: 'USDC',
35+
coinMinimalDenom: 'uusdc',
36+
coinDecimals: 6,
37+
coinGeckoId: 'usd-coin'
38+
},
39+
{
40+
coinDenom: 'ATOM',
41+
coinMinimalDenom: 'uatom',
42+
coinDecimals: 6,
43+
coinGeckoId: 'cosmos'
44+
},
45+
{
46+
coinDenom: 'WETH',
47+
coinMinimalDenom: 'ibc/C2A89D98873BB55B62CE86700DFACA646EC80352E8D03CC6CF34DD44E46DC75D',
48+
coinDecimals: 18,
49+
coinGeckoId: 'weth'
50+
},
51+
{
52+
coinDenom: 'WBTC',
53+
coinMinimalDenom: 'ibc/42BCC21A2B784E813F8878739FD32B4AA2D0A68CAD94F4C88B9EA98609AB0CCD',
54+
coinDecimals: 8,
55+
coinGeckoId: 'bitcoin'
56+
},
57+
{
58+
coinDenom: 'aUSDC',
59+
coinMinimalDenom: 'ibc/6D45A5CD1AADE4B527E459025AC1A5AEF41AE99091EF3069F3FEAACAFCECCD21',
60+
coinDecimals: 6,
61+
coinGeckoId: 'usd-coin'
62+
},
63+
{
64+
coinDenom: 'UST2',
65+
coinMinimalDenom: baseDenomTokenId,
66+
coinDecimals: 6
67+
}
68+
],
69+
feeCurrencies: [
70+
{
71+
coinDenom: 'SEI',
72+
coinMinimalDenom: 'usei',
73+
coinDecimals: 6
74+
}
75+
],
76+
stakeCurrency: {
77+
coinDenom: 'SEI',
78+
coinMinimalDenom: 'usei',
79+
coinDecimals: 6
80+
},
81+
coinType: 118,
82+
features: ['stargate', 'ibc-transfer', 'cosmwasm']
83+
};
84+
};
8785

8886
const KEPLR_WALLET: SupportedWallet = {
89-
windowKey: "keplr",
87+
windowKey: 'keplr'
9088
};
9189

9290
const LEAP_WALLET: SupportedWallet = {
93-
windowKey: "leap",
91+
windowKey: 'leap'
9492
};
9593

96-
export const SUPPORTED_WALLETS: SupportedWallet[] = [
97-
KEPLR_WALLET,
98-
LEAP_WALLET,
99-
];
94+
export const SUPPORTED_WALLETS: SupportedWallet[] = [KEPLR_WALLET, LEAP_WALLET];

src/wallet/connection.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { KEPLR_CHAIN_SUGGEST } from './config';
1+
import { getChainSuggest } from './config';
22
import { WalletConnect, WalletWindowKey } from './types';
33

44
declare global {
@@ -8,16 +8,16 @@ declare global {
88
}
99
}
1010

11-
export const connect = async (inputWallet: WalletWindowKey): Promise<WalletConnect | undefined> => {
11+
export const connect = async (inputWallet: WalletWindowKey, chainId?: string, restUrl?: string, rpcUrl?: string): Promise<WalletConnect | undefined> => {
1212
switch (inputWallet) {
1313
case 'keplr':
14-
await window.keplr.experimentalSuggestChain(KEPLR_CHAIN_SUGGEST);
14+
await window.keplr.experimentalSuggestChain(getChainSuggest(chainId, restUrl, rpcUrl));
1515
break;
1616
}
1717

1818
if (typeof window === 'undefined' || !window) return;
1919

20-
const offlineSigner = await window[inputWallet].getOfflineSigner('atlantic-1');
20+
const offlineSigner = await window[inputWallet].getOfflineSigner(chainId);
2121
const accounts = await offlineSigner.getAccounts();
2222

2323
return { offlineSigner, accounts };

0 commit comments

Comments
 (0)