Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit 8d074d4

Browse files
authored
Merge pull request #431 from blocto/fix/multiple-chain-setting
fix: multiple chain setting
2 parents bd0eb8e + 79dade9 commit 8d074d4

File tree

11 files changed

+498
-15
lines changed

11 files changed

+498
-15
lines changed

.changeset/cold-eggs-film.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@blocto/sdk': patch
3+
---
4+
5+
fix story tesnet url, fix multiple chain setting, update polygon url
6+

.changeset/pre.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
"mode": "exit",
33
"tag": "beta",
44
"initialVersions": {
5-
"@blocto/aptos-wallet-adapter-plugin": "0.2.10",
5+
"@blocto/aptos-wallet-adapter-plugin": "0.2.11-beta.0",
66
"@blocto/connectkit-connector": "0.2.3",
7-
"@blocto/rainbowkit-connector": "2.0.2",
8-
"@blocto/wagmi-connector": "2.0.4",
9-
"@blocto/web3-react-connector": "1.0.8",
7+
"@blocto/rainbowkit-connector": "2.0.3-beta.0",
8+
"@blocto/wagmi-connector": "2.0.5-beta.0",
9+
"@blocto/web3-react-connector": "1.0.9-beta.0",
1010
"@blocto/web3modal-connector": "0.1.4",
11-
"@blocto/sdk": "0.10.3",
11+
"@blocto/sdk": "0.10.4-beta.1",
1212
"@blocto/dappauth": "2.2.2",
1313
"eslint-config-custom": "0.0.0",
1414
"tsconfig": "0.0.0"
1515
},
1616
"changesets": [
17-
"nasty-cats-greet"
17+
"nasty-cats-greet",
18+
"yellow-rockets-judge"
1819
]
1920
}

.changeset/yellow-rockets-judge.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@blocto/sdk': patch
3+
---
4+
5+
fix multiple chain setting

packages/blocto-sdk/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @blocto/sdk
22

3+
## 0.10.4-beta.1
4+
5+
### Patch Changes
6+
7+
- 2e2164e: fix multiple chain setting
8+
39
## 0.10.4-beta.0
410

511
### Patch Changes

packages/blocto-sdk/jest.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
'^.+\\.(ts|tsx)?$': 'ts-jest',
77
'^.+\\.(js|jsx)$': 'babel-jest',
88
},
9-
transformIgnorePatterns: ['node_modules/(?!variables/.*)'],
9+
testPathIgnorePatterns: ['node_modules/(?!variables/.*)', '/fixtures/', '\\.d\\.ts$'],
1010
automock: false,
1111
resetMocks: false,
1212
};

packages/blocto-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@blocto/sdk",
3-
"version": "0.10.4-beta.0",
3+
"version": "0.10.4-beta.1",
44
"repository": "git@github.com:portto/blocto-sdk.git",
55
"author": "Chiaki.C",
66
"license": "MIT",
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import EthereumProvider from '../providers/ethereum';
2+
import { getEvmSupport } from '../lib/getEvmSupport';
3+
import { getEvmSupportList } from './fixtures/getEvmSupport';
4+
jest.mock('../lib/getEvmSupport');
5+
6+
describe('Testing BloctoSDK ethereum provider initialization and network loading', () => {
7+
beforeEach(() => {
8+
(getEvmSupport as jest.Mock).mockResolvedValue(getEvmSupportList);
9+
});
10+
11+
test('should initialize with unloadedNetwork', () => {
12+
const ethereumWithSwitchable = new EthereumProvider({
13+
defaultChainId: '0xaa36a7',
14+
switchableChains: [
15+
{
16+
chainId: '0xaa36a7',
17+
rpcUrls: ['https://ethereum-sepolia.blockpi.network/v1/rpc/public'],
18+
},
19+
{
20+
chainId: '0x61',
21+
rpcUrls: ['https://data-seed-prebsc-1-s1.binance.org:8545'],
22+
},
23+
],
24+
});
25+
26+
expect(ethereumWithSwitchable['_blocto'].unloadedNetwork).toBeDefined();
27+
expect(
28+
ethereumWithSwitchable['_blocto']?.unloadedNetwork?.[0].chainId
29+
).toBe('0xaa36a7');
30+
expect(
31+
ethereumWithSwitchable['_blocto']?.unloadedNetwork?.[1].chainId
32+
).toBe('0x61');
33+
expect(ethereumWithSwitchable['_blocto'].unloadedNetwork?.length).toBe(2);
34+
});
35+
36+
test('get support chain list', async () => {
37+
const ethereum = new EthereumProvider({
38+
chainId: '0xaa36a7',
39+
rpc: 'https://ethereum-sepolia.blockpi.network/v1/rpc/public',
40+
});
41+
const supportedChains = await ethereum.supportChainList();
42+
expect(supportedChains).toContainEqual({
43+
chainId: '11155111',
44+
chainName: 'Sepolia',
45+
});
46+
});
47+
48+
test('should add chain and switch to it', async () => {
49+
const ethereum = new EthereumProvider({
50+
chainId: '0xaa36a7',
51+
rpc: 'https://ethereum-sepolia.blockpi.network/v1/rpc/public',
52+
});
53+
await expect(
54+
ethereum.request({
55+
method: 'wallet_switchEthereumChain',
56+
params: [{ chainId: '0x61' }],
57+
})
58+
).rejects.toThrow(
59+
'Unrecognized chain ID "97". Try adding the chain using wallet_addEthereumChain first.'
60+
);
61+
62+
await ethereum.request({
63+
method: 'wallet_addEthereumChain',
64+
params: [
65+
{
66+
chainId: '0x61',
67+
rpcUrls: ['https://data-seed-prebsc-1-s1.binance.org:8545'],
68+
},
69+
],
70+
});
71+
await ethereum.request({
72+
method: 'wallet_switchEthereumChain',
73+
params: [{ chainId: '0x61' }],
74+
});
75+
expect(ethereum.chainId).toBe('0x61');
76+
});
77+
78+
test('create sdk instance with switchableChains and switch to it', async () => {
79+
const ethereum = new EthereumProvider({
80+
defaultChainId: '0xaa36a7',
81+
switchableChains: [
82+
{
83+
chainId: '0xaa36a7',
84+
rpcUrls: ['https://ethereum-sepolia.blockpi.network/v1/rpc/public'],
85+
},
86+
{
87+
chainId: '0x61',
88+
rpcUrls: ['https://data-seed-prebsc-1-s1.binance.org:8545'],
89+
},
90+
],
91+
});
92+
await ethereum.request({
93+
method: 'wallet_switchEthereumChain',
94+
params: [{ chainId: '0x61' }],
95+
});
96+
expect(ethereum.chainId).toBe('0x61');
97+
});
98+
test('create sdk instance with switchableChains and call eth_accounts', async () => {
99+
const ethereum = new EthereumProvider({
100+
defaultChainId: '0xaa36a7',
101+
switchableChains: [
102+
{
103+
chainId: '0xaa36a7',
104+
rpcUrls: ['https://ethereum-sepolia.blockpi.network/v1/rpc/public'],
105+
},
106+
{
107+
chainId: '0x61',
108+
rpcUrls: ['https://data-seed-prebsc-1-s1.binance.org:8545'],
109+
},
110+
],
111+
});
112+
// Trigger the loading of switchable networks
113+
await ethereum.request({
114+
method: 'eth_accounts',
115+
});
116+
expect(ethereum.chainId).toBe('0xaa36a7');
117+
// should remove unloadedNetwork after loading
118+
expect(ethereum['_blocto'].unloadedNetwork).toBeUndefined();
119+
});
120+
121+
test('should not call loadSwitchableNetwork if unloadedNetwork is empty', async () => {
122+
const ethereum = new EthereumProvider({
123+
chainId: '0xaa36a7',
124+
rpc: 'https://ethereum-sepolia.blockpi.network/v1/rpc/public',
125+
});
126+
const loadSwitchableNetworkSpy = jest.spyOn(ethereum, 'loadSwitchableNetwork');
127+
128+
await ethereum.request({ method: 'eth_accounts' });
129+
130+
expect(loadSwitchableNetworkSpy).not.toHaveBeenCalled();
131+
});
132+
});

0 commit comments

Comments
 (0)