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

fix: multiplechain setting and update rpc url #435

Merged
merged 15 commits into from
Oct 14, 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
6 changes: 6 additions & 0 deletions .changeset/cold-eggs-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@blocto/sdk': patch
---

fix story tesnet url, fix multiple chain setting, update polygon url

5 changes: 5 additions & 0 deletions .changeset/nasty-cats-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@blocto/sdk': patch
---

support Story testnet
20 changes: 20 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"mode": "exit",
"tag": "beta",
"initialVersions": {
"@blocto/aptos-wallet-adapter-plugin": "0.2.11-beta.0",
"@blocto/connectkit-connector": "0.2.3",
"@blocto/rainbowkit-connector": "2.0.3-beta.0",
"@blocto/wagmi-connector": "2.0.5-beta.0",
"@blocto/web3-react-connector": "1.0.9-beta.0",
"@blocto/web3modal-connector": "0.1.4",
"@blocto/sdk": "0.10.4-beta.1",
"@blocto/dappauth": "2.2.2",
"eslint-config-custom": "0.0.0",
"tsconfig": "0.0.0"
},
"changesets": [
"nasty-cats-greet",
"yellow-rockets-judge"
]
}
5 changes: 5 additions & 0 deletions .changeset/yellow-rockets-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@blocto/sdk': patch
---

fix multiple chain setting
7 changes: 7 additions & 0 deletions adapters/aptos-wallet-adapter-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @blocto/aptos-wallet-adapter-plugin

## 0.2.11-beta.0

### Patch Changes

- Updated dependencies [ec87223]
- @blocto/[email protected]

## 0.2.10

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions adapters/aptos-wallet-adapter-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blocto/aptos-wallet-adapter-plugin",
"version": "0.2.10",
"version": "0.2.11-beta.0",
"description": "Blocto Wallet plugin to use with Aptos Wallet Adapter",
"author": "Blocto Wallet",
"main": "./dist/index.js",
Expand All @@ -19,7 +19,7 @@
},
"dependencies": {
"@aptos-labs/wallet-adapter-core": "^2.2.0",
"@blocto/sdk": "^0.10.3",
"@blocto/sdk": "^0.10.4-beta.0",
"aptos": "^1.9.1"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions adapters/rainbowkit-connector/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @blocto/rainbowkit-connector

## 2.0.3-beta.0

### Patch Changes

- @blocto/[email protected]

## 2.0.2

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions adapters/rainbowkit-connector/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blocto/rainbowkit-connector",
"version": "2.0.2",
"version": "2.0.3-beta.0",
"description": "blocto wallet connector to use rainbowkit",
"author": "Blocto Wallet",
"main": "./dist/index.js",
Expand Down Expand Up @@ -34,7 +34,7 @@
},
"dependencies": {
"@rainbow-me/rainbowkit": "^2.0.5",
"@blocto/wagmi-connector": "^2.0.4"
"@blocto/wagmi-connector": "^2.0.5-beta.0"
},
"devDependencies": {
"@types/jest": "^29.5.2",
Expand Down
7 changes: 7 additions & 0 deletions adapters/wagmi-connector/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @blocto/wagmi-connector

## 2.0.5-beta.0

### Patch Changes

- Updated dependencies [ec87223]
- @blocto/[email protected]

## 2.0.4

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions adapters/wagmi-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@blocto/wagmi-connector",
"description": "Blocto wallet connector extend from wagmi Connector",
"author": "Calvin Chang",
"version": "2.0.4",
"version": "2.0.5-beta.0",
"type": "module",
"main": "./dist/index.umd.cjs",
"module": "./dist/index.js",
Expand Down Expand Up @@ -32,7 +32,7 @@
"/dist"
],
"dependencies": {
"@blocto/sdk": "^0.10.3"
"@blocto/sdk": "^0.10.4-beta.0"
},
"peerDependencies": {
"@wagmi/core": "^2.2.0",
Expand Down
7 changes: 7 additions & 0 deletions adapters/web3-react-connector/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @blocto/web3-react-connector

## 1.0.9-beta.0

### Patch Changes

- Updated dependencies [ec87223]
- @blocto/[email protected]

## 1.0.8

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions adapters/web3-react-connector/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blocto/web3-react-connector",
"version": "1.0.8",
"version": "1.0.9-beta.0",
"description": "A Blocto SDK connector for web3-react",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down Expand Up @@ -43,7 +43,7 @@
"url": "git://github.com/portto/blocto-sdk.git"
},
"dependencies": {
"@blocto/sdk": "^0.10.3",
"@blocto/sdk": "^0.10.4-beta.0",
"@web3-react/types": "^8.1.2-beta.0"
},
"devDependencies": {
Expand Down
12 changes: 12 additions & 0 deletions packages/blocto-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @blocto/sdk

## 0.10.4-beta.1

### Patch Changes

- 2e2164e: fix multiple chain setting

## 0.10.4-beta.0

### Patch Changes

- ec87223: support Story testnet

## 0.10.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/blocto-sdk/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
'^.+\\.(ts|tsx)?$': 'ts-jest',
'^.+\\.(js|jsx)$': 'babel-jest',
},
transformIgnorePatterns: ['node_modules/(?!variables/.*)'],
testPathIgnorePatterns: ['node_modules/(?!variables/.*)', '/fixtures/', '\\.d\\.ts$'],
automock: false,
resetMocks: false,
};
2 changes: 1 addition & 1 deletion packages/blocto-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blocto/sdk",
"version": "0.10.3",
"version": "0.10.4-beta.1",
"repository": "[email protected]:portto/blocto-sdk.git",
"author": "Chiaki.C",
"license": "MIT",
Expand Down
132 changes: 132 additions & 0 deletions packages/blocto-sdk/src/__tests__/ethereum.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import EthereumProvider from '../providers/ethereum';
import { getEvmSupport } from '../lib/getEvmSupport';
import { getEvmSupportList } from './fixtures/getEvmSupport';
jest.mock('../lib/getEvmSupport');

describe('Testing BloctoSDK ethereum provider initialization and network loading', () => {
beforeEach(() => {
(getEvmSupport as jest.Mock).mockResolvedValue(getEvmSupportList);
});

test('should initialize with unloadedNetwork', () => {
const ethereumWithSwitchable = new EthereumProvider({
defaultChainId: '0xaa36a7',
switchableChains: [
{
chainId: '0xaa36a7',
rpcUrls: ['https://ethereum-sepolia.blockpi.network/v1/rpc/public'],
},
{
chainId: '0x61',
rpcUrls: ['https://data-seed-prebsc-1-s1.binance.org:8545'],
},
],
});

expect(ethereumWithSwitchable['_blocto'].unloadedNetwork).toBeDefined();
expect(
ethereumWithSwitchable['_blocto']?.unloadedNetwork?.[0].chainId
).toBe('0xaa36a7');
expect(
ethereumWithSwitchable['_blocto']?.unloadedNetwork?.[1].chainId
).toBe('0x61');
expect(ethereumWithSwitchable['_blocto'].unloadedNetwork?.length).toBe(2);
});

test('get support chain list', async () => {
const ethereum = new EthereumProvider({
chainId: '0xaa36a7',
rpc: 'https://ethereum-sepolia.blockpi.network/v1/rpc/public',
});
const supportedChains = await ethereum.supportChainList();
expect(supportedChains).toContainEqual({
chainId: '11155111',
chainName: 'Sepolia',
});
});

test('should add chain and switch to it', async () => {
const ethereum = new EthereumProvider({
chainId: '0xaa36a7',
rpc: 'https://ethereum-sepolia.blockpi.network/v1/rpc/public',
});
await expect(
ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x61' }],
})
).rejects.toThrow(
'Unrecognized chain ID "97". Try adding the chain using wallet_addEthereumChain first.'
);

await ethereum.request({
method: 'wallet_addEthereumChain',
params: [
{
chainId: '0x61',
rpcUrls: ['https://data-seed-prebsc-1-s1.binance.org:8545'],
},
],
});
await ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x61' }],
});
expect(ethereum.chainId).toBe('0x61');
});

test('create sdk instance with switchableChains and switch to it', async () => {
const ethereum = new EthereumProvider({
defaultChainId: '0xaa36a7',
switchableChains: [
{
chainId: '0xaa36a7',
rpcUrls: ['https://ethereum-sepolia.blockpi.network/v1/rpc/public'],
},
{
chainId: '0x61',
rpcUrls: ['https://data-seed-prebsc-1-s1.binance.org:8545'],
},
],
});
await ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x61' }],
});
expect(ethereum.chainId).toBe('0x61');
});
test('create sdk instance with switchableChains and call eth_accounts', async () => {
const ethereum = new EthereumProvider({
defaultChainId: '0xaa36a7',
switchableChains: [
{
chainId: '0xaa36a7',
rpcUrls: ['https://ethereum-sepolia.blockpi.network/v1/rpc/public'],
},
{
chainId: '0x61',
rpcUrls: ['https://data-seed-prebsc-1-s1.binance.org:8545'],
},
],
});
// Trigger the loading of switchable networks
await ethereum.request({
method: 'eth_accounts',
});
expect(ethereum.chainId).toBe('0xaa36a7');
// should remove unloadedNetwork after loading
expect(ethereum['_blocto'].unloadedNetwork).toBeUndefined();
});

test('should not call loadSwitchableNetwork if unloadedNetwork is empty', async () => {
const ethereum = new EthereumProvider({
chainId: '0xaa36a7',
rpc: 'https://ethereum-sepolia.blockpi.network/v1/rpc/public',
});
const loadSwitchableNetworkSpy = jest.spyOn(ethereum, 'loadSwitchableNetwork');

await ethereum.request({ method: 'eth_accounts' });

expect(loadSwitchableNetworkSpy).not.toHaveBeenCalled();
});
});
Loading
Loading