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

Commit d7cdcd5

Browse files
authored
Merge pull request #386 from blocto/release/0118.2
Release: Merge to publish new version to npm
2 parents c9f52f0 + 14ae6bb commit d7cdcd5

File tree

14 files changed

+1026
-253
lines changed

14 files changed

+1026
-253
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
- name: Checkout Repo
1616
uses: actions/checkout@v3
1717

18-
- name: Setup Node.js 16
18+
- name: Setup Node.js 18
1919
uses: actions/setup-node@v3
2020
with:
21-
node-version: 16
21+
node-version: 18
2222

2323
- name: Install Dependencies
2424
run: yarn

.github/workflows/release-branch.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ jobs:
2727
restore-keys: |
2828
${{ runner.os }}-turbo-
2929
30-
- name: Setup Node.js 16
30+
- name: Setup Node.js 18
3131
uses: actions/setup-node@v3
3232
with:
33-
node-version: 16
33+
node-version: 18
3434

3535
- name: Install Dependencies
3636
run: yarn

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222
restore-keys: |
2323
${{ runner.os }}-turbo-
2424
25-
- name: Setup Node.js 16
25+
- name: Setup Node.js 18
2626
uses: actions/setup-node@v3
2727
with:
28-
node-version: 16
28+
node-version: 18
2929

3030
- name: Install dependencies
3131
run: yarn

adapters/connectkit-connector/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"/dist"
3131
],
3232
"dependencies": {
33-
"@blocto/wagmi-connector": "^1.3.1"
33+
"@blocto/wagmi-connector": "npm:@blocto/wagmi-connector@^1.3.1"
3434
},
3535
"peerDependencies": {
3636
"connectkit": "^1.5.3",

adapters/rainbowkit-connector/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"dependencies": {
3636
"@rainbow-me/rainbowkit": "^1.0.8",
37-
"@blocto/wagmi-connector": "^1.3.1"
37+
"@blocto/wagmi-connector": "npm:@blocto/wagmi-connector@^1.3.1"
3838
},
3939
"devDependencies": {
4040
"@types/jest": "^29.5.2",

adapters/wagmi-connector/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# @blocto/wagmi-connector
22

3+
## 2.0.0
4+
5+
### Major Changes
6+
7+
- 196aee7: blocto connector support wagmi v2
8+
9+
## 2.0.0-beta.0
10+
11+
### Major Changes
12+
13+
- 196aee7: blocto connector support wagmi v2
14+
315
## 1.3.1
416

517
### Patch Changes

adapters/wagmi-connector/package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@blocto/wagmi-connector",
33
"description": "Blocto wallet connector extend from wagmi Connector",
44
"author": "Calvin Chang",
5-
"version": "1.3.1",
5+
"version": "2.0.0",
66
"type": "module",
77
"main": "./dist/index.umd.cjs",
88
"module": "./dist/index.js",
@@ -14,15 +14,19 @@
1414
},
1515
"scripts": {
1616
"build": "tsc && vite build",
17-
"lint": "eslint src --ext .ts"
17+
"lint": "eslint src --ext .ts",
18+
"test": "vitest run --coverage"
1819
},
1920
"devDependencies": {
2021
"@types/node": "^20.2.5",
22+
"@vitest/coverage-v8": "^1.2.0",
23+
"@wagmi/chains": "^1.8.0",
24+
"@wagmi/core": "^2.2.0",
2125
"typescript": "^5.1.3",
26+
"viem": "^2.x",
2227
"vite": "^4.3.9",
2328
"vite-plugin-dts": "^2.3.0",
24-
"@wagmi/core": "^1.3.9",
25-
"viem": "^1.5.4"
29+
"vitest": "^1.2.0"
2630
},
2731
"files": [
2832
"/dist"
@@ -31,7 +35,7 @@
3135
"@blocto/sdk": "^0.9.1"
3236
},
3337
"peerDependencies": {
34-
"@wagmi/core": ">=1",
35-
"viem": ">=1"
38+
"@wagmi/core": "^2.2.0",
39+
"viem": "2.x"
3640
}
3741
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
5+
import { expect, test, describe, vi, beforeEach, afterEach } from 'vitest';
6+
import { createConfig } from '@wagmi/core';
7+
import { polygonMumbai, arbitrumGoerli } from '@wagmi/chains';
8+
import * as viem from 'viem';
9+
import { normalizeChainId } from '@wagmi/core';
10+
import { blocto } from './index';
11+
12+
vi.mock('viem');
13+
14+
describe('blocto-connector', () => {
15+
let connector: any;
16+
beforeEach(() => {
17+
const config = createConfig({
18+
chains: [polygonMumbai, arbitrumGoerli],
19+
pollingInterval: 100,
20+
storage: null,
21+
transports: {
22+
[polygonMumbai.id]: viem.http(),
23+
[arbitrumGoerli.id]: viem.http(),
24+
},
25+
});
26+
27+
const connectorFn = blocto();
28+
connector = config._internal.connectors.setup(connectorFn);
29+
});
30+
31+
afterEach(() => {
32+
connector = null;
33+
});
34+
35+
test('setup', () => {
36+
expect(connector.name).toEqual('Blocto');
37+
});
38+
39+
test('connect', async () => {
40+
const chainId = 1;
41+
const accounts = ['0xc61B4Aa62E5FD40cceB08C602Eb5D157b257b49a'];
42+
const provider = {
43+
request: vi.fn().mockResolvedValue(accounts),
44+
};
45+
connector.getProvider = vi.fn().mockResolvedValue(provider);
46+
connector.getAccounts = vi.fn().mockResolvedValue(accounts);
47+
connector.getChainId = vi.fn().mockResolvedValue(chainId);
48+
49+
const result = await connector.connect({ chainId });
50+
51+
expect(result).toEqual({ accounts, chainId });
52+
expect(connector.getProvider).toHaveBeenCalledWith({ chainId });
53+
expect(provider.request).toHaveBeenCalledWith({
54+
method: 'eth_requestAccounts',
55+
});
56+
});
57+
58+
test('disconnect', async () => {
59+
const provider = {
60+
request: vi.fn().mockResolvedValue(undefined),
61+
};
62+
connector.getProvider = vi.fn().mockResolvedValue(provider);
63+
64+
await connector.disconnect();
65+
66+
expect(connector.getProvider).toHaveBeenCalled();
67+
expect(provider.request).toHaveBeenCalledWith({
68+
method: 'wallet_disconnect',
69+
});
70+
});
71+
72+
test('getAccounts', async () => {
73+
const accounts = ['0xc61B4Aa62E5FD40cceB08C602Eb5D157b257b49a'];
74+
const provider = {
75+
request: vi.fn().mockResolvedValue(accounts),
76+
};
77+
connector.getProvider = vi.fn().mockResolvedValue(provider);
78+
vi.spyOn(viem, 'getAddress').mockImplementation((x) => x as `0x${string}`);
79+
80+
const result = await connector.getAccounts();
81+
82+
expect(result).toEqual(['0xc61B4Aa62E5FD40cceB08C602Eb5D157b257b49a']);
83+
expect(connector.getProvider).toHaveBeenCalled();
84+
expect(provider.request).toHaveBeenCalledWith({ method: 'eth_accounts' });
85+
});
86+
87+
test('getChainId', async () => {
88+
const chainId = '0x1';
89+
const provider = {
90+
chainId: undefined,
91+
request: vi.fn().mockResolvedValue(chainId),
92+
};
93+
connector.getProvider = vi.fn().mockResolvedValue(provider);
94+
95+
const result = await connector.getChainId();
96+
97+
expect(result).toEqual(normalizeChainId(chainId));
98+
expect(connector.getProvider).toHaveBeenCalled();
99+
expect(provider.request).toHaveBeenCalledWith({ method: 'eth_chainId' });
100+
});
101+
102+
test('isAuthorized', async () => {
103+
const accounts = ['0xc61B4Aa62E5FD40cceB08C602Eb5D157b257b49a'];
104+
connector.getAccounts = vi.fn().mockResolvedValue(accounts);
105+
106+
const result = await connector.isAuthorized();
107+
108+
expect(result).toEqual(false);
109+
});
110+
111+
test('switchChain', async () => {
112+
const chainId = arbitrumGoerli.id;
113+
const provider = {
114+
request: vi.fn().mockResolvedValue(undefined),
115+
supportChainList: vi.fn().mockResolvedValue(
116+
[polygonMumbai, arbitrumGoerli].map(({ id, name }) => ({
117+
chainId: id,
118+
chainName: name,
119+
}))
120+
),
121+
};
122+
connector.getProvider = vi.fn().mockResolvedValue(provider);
123+
vi.spyOn(viem, 'numberToHex').mockReturnValue(viem.numberToHex(chainId));
124+
125+
const chain = await connector.switchChain({ chainId });
126+
127+
expect(connector.getProvider).toHaveBeenCalled();
128+
expect(provider.request).toHaveBeenCalledWith({
129+
method: 'wallet_addEthereumChain',
130+
params: [
131+
{
132+
chainId: viem.numberToHex(chainId),
133+
rpcUrls: arbitrumGoerli.rpcUrls.default.http,
134+
},
135+
],
136+
});
137+
expect(provider.request).toHaveBeenCalledWith({
138+
method: 'wallet_switchEthereumChain',
139+
params: [
140+
{
141+
chainId: viem.numberToHex(chainId),
142+
},
143+
],
144+
});
145+
expect(chain.id).toEqual(chainId);
146+
});
147+
});

0 commit comments

Comments
 (0)