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

Commit e1f287d

Browse files
authored
Merge pull request #404 from blocto/release/0318
Release: Merge to publish new version to npm
2 parents 56c377f + 41de6e4 commit e1f287d

File tree

13 files changed

+187
-30
lines changed

13 files changed

+187
-30
lines changed

adapters/aptos-wallet-adapter-plugin/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# @blocto/aptos-wallet-adapter-plugin
22

3+
## 0.2.9
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [bd6b11c]
8+
- Updated dependencies [74abbd7]
9+
- @blocto/sdk@0.10.0
10+
11+
## 0.2.9-beta.0
12+
13+
### Patch Changes
14+
15+
- Updated dependencies [74abbd7]
16+
- @blocto/sdk@0.10.0-beta.0
17+
318
## 0.2.8
419

520
### Patch Changes

adapters/aptos-wallet-adapter-plugin/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@blocto/aptos-wallet-adapter-plugin",
3-
"version": "0.2.8",
3+
"version": "0.2.9",
44
"description": "Blocto Wallet plugin to use with Aptos Wallet Adapter",
55
"author": "Blocto Wallet",
66
"main": "./dist/index.js",
@@ -19,7 +19,7 @@
1919
},
2020
"dependencies": {
2121
"@aptos-labs/wallet-adapter-core": "^2.2.0",
22-
"@blocto/sdk": "^0.9.1",
22+
"@blocto/sdk": "^0.10.0",
2323
"aptos": "^1.9.1"
2424
},
2525
"devDependencies": {

adapters/wagmi-connector/CHANGELOG.md

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

3+
## 2.0.2
4+
5+
### Patch Changes
6+
7+
- 5191913: adjust the usage of getAddress function
8+
- Updated dependencies [bd6b11c]
9+
- Updated dependencies [74abbd7]
10+
- @blocto/sdk@0.10.0
11+
12+
## 2.0.2-beta.0
13+
14+
### Patch Changes
15+
16+
- 5191913: adjust the usage of getAddress function
17+
- Updated dependencies [74abbd7]
18+
- @blocto/sdk@0.10.0-beta.0
19+
320
## 2.0.1
421

522
### Patch Changes

adapters/wagmi-connector/package.json

Lines changed: 2 additions & 2 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": "2.0.1",
5+
"version": "2.0.2",
66
"type": "module",
77
"main": "./dist/index.umd.cjs",
88
"module": "./dist/index.js",
@@ -32,7 +32,7 @@
3232
"/dist"
3333
],
3434
"dependencies": {
35-
"@blocto/sdk": "^0.9.1"
35+
"@blocto/sdk": "^0.10.0"
3636
},
3737
"peerDependencies": {
3838
"@wagmi/core": "^2.2.0",

adapters/wagmi-connector/src/connector.test.ts

Lines changed: 89 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
/**
2-
* @vitest-environment jsdom
3-
*/
4-
51
import { expect, test, describe, vi, beforeEach, afterEach } from 'vitest';
62
import { createConfig } from '@wagmi/core';
73
import { polygonMumbai, arbitrumGoerli } from '@wagmi/chains';
8-
import * as viem from 'viem';
4+
import { SwitchChainError, http, numberToHex } from 'viem';
95
import { normalizeChainId } from '@wagmi/core';
10-
import { blocto } from './index';
6+
import { blocto } from './';
117

12-
vi.mock('viem');
8+
const walletProvider = {
9+
on: vi.fn(),
10+
};
1311

1412
describe('blocto-connector', () => {
1513
let connector: any;
@@ -19,13 +17,11 @@ describe('blocto-connector', () => {
1917
pollingInterval: 100,
2018
storage: null,
2119
transports: {
22-
[polygonMumbai.id]: viem.http(),
23-
[arbitrumGoerli.id]: viem.http(),
20+
[polygonMumbai.id]: http(),
21+
[arbitrumGoerli.id]: http(),
2422
},
2523
});
26-
27-
const connectorFn = blocto();
28-
connector = config._internal.connectors.setup(connectorFn);
24+
connector = config._internal.connectors.setup(blocto());
2925
});
3026

3127
afterEach(() => {
@@ -55,6 +51,19 @@ describe('blocto-connector', () => {
5551
});
5652
});
5753

54+
test('catch error when user decline to connect', () => {
55+
const chainId = 1;
56+
const userRejectedRequest = new Error('User rejected request');
57+
const provider = {
58+
request: vi.fn().mockImplementation(() => {
59+
throw userRejectedRequest;
60+
}),
61+
};
62+
connector.getProvider = vi.fn().mockResolvedValue(provider);
63+
64+
expect(connector.connect({ chainId })).rejects.toThrow(userRejectedRequest);
65+
});
66+
5867
test('disconnect', async () => {
5968
const provider = {
6069
request: vi.fn().mockResolvedValue(undefined),
@@ -75,7 +84,6 @@ describe('blocto-connector', () => {
7584
request: vi.fn().mockResolvedValue(accounts),
7685
};
7786
connector.getProvider = vi.fn().mockResolvedValue(provider);
78-
vi.spyOn(viem, 'getAddress').mockImplementation((x) => x as `0x${string}`);
7987

8088
const result = await connector.getAccounts();
8189

@@ -99,6 +107,30 @@ describe('blocto-connector', () => {
99107
expect(provider.request).toHaveBeenCalledWith({ method: 'eth_chainId' });
100108
});
101109

110+
test('getProvider', async () => {
111+
vi.mock('@blocto/sdk', () => ({
112+
default: vi.fn().mockImplementation(() => ({
113+
ethereum: walletProvider,
114+
})),
115+
}));
116+
117+
const chainId = 1;
118+
const result = await connector.getProvider({ chainId });
119+
120+
expect(result).toEqual(walletProvider);
121+
expect(walletProvider.on).toHaveBeenCalledWith(
122+
'accountsChanged',
123+
expect.any(Function)
124+
);
125+
expect(walletProvider.on).toHaveBeenCalledWith(
126+
'chainChanged',
127+
expect.any(Function)
128+
);
129+
expect(walletProvider.on).toHaveBeenCalledWith(
130+
'disconnect',
131+
expect.any(Function)
132+
);
133+
});
102134
test('isAuthorized', async () => {
103135
const accounts = ['0xc61B4Aa62E5FD40cceB08C602Eb5D157b257b49a'];
104136
connector.getAccounts = vi.fn().mockResolvedValue(accounts);
@@ -120,7 +152,6 @@ describe('blocto-connector', () => {
120152
),
121153
};
122154
connector.getProvider = vi.fn().mockResolvedValue(provider);
123-
vi.spyOn(viem, 'numberToHex').mockReturnValue(viem.numberToHex(chainId));
124155

125156
const chain = await connector.switchChain({ chainId });
126157

@@ -129,19 +160,57 @@ describe('blocto-connector', () => {
129160
method: 'wallet_addEthereumChain',
130161
params: [
131162
{
132-
chainId: viem.numberToHex(chainId),
163+
chainId: numberToHex(chainId),
133164
rpcUrls: arbitrumGoerli.rpcUrls.default.http,
134165
},
135166
],
136167
});
137168
expect(provider.request).toHaveBeenCalledWith({
138169
method: 'wallet_switchEthereumChain',
139-
params: [
140-
{
141-
chainId: viem.numberToHex(chainId),
142-
},
143-
],
170+
params: [{ chainId: numberToHex(chainId) }],
144171
});
145172
expect(chain.id).toEqual(chainId);
146173
});
174+
175+
test('catch error when switching to unConfigured chain', async () => {
176+
const unConfiguredChainId = 111111;
177+
const provider = {
178+
request: vi.fn().mockResolvedValue(undefined),
179+
supportChainList: vi.fn().mockResolvedValue(
180+
[polygonMumbai, arbitrumGoerli].map(({ id, name }) => ({
181+
chainId: id,
182+
chainName: name,
183+
}))
184+
),
185+
};
186+
connector.getProvider = vi.fn().mockResolvedValue(provider);
187+
const expectError = new SwitchChainError(
188+
new Error(`Chain not in config: ${numberToHex(unConfiguredChainId)}`)
189+
);
190+
191+
expect(
192+
connector.switchChain({ chainId: unConfiguredChainId })
193+
).rejects.toThrow(expectError);
194+
});
195+
196+
test('catch error when switching to blocto unsupported chain', async () => {
197+
const unsupportedChainId = arbitrumGoerli.id;
198+
const provider = {
199+
request: vi.fn().mockResolvedValue(undefined),
200+
supportChainList: vi.fn().mockResolvedValue(
201+
[polygonMumbai].map(({ id, name }) => ({
202+
chainId: id,
203+
chainName: name,
204+
}))
205+
),
206+
};
207+
connector.getProvider = vi.fn().mockResolvedValue(provider);
208+
const expectError = new SwitchChainError(
209+
new Error(`Blocto unsupported chain: ${numberToHex(unsupportedChainId)}`)
210+
);
211+
212+
expect(
213+
connector.switchChain({ chainId: unsupportedChainId })
214+
).rejects.toThrow(expectError);
215+
});
147216
});

adapters/wagmi-connector/src/connector.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function blocto({ appId }: BloctoParameters = {}) {
7070
method: 'eth_accounts',
7171
})) as string[];
7272

73-
return accounts.map(getAddress);
73+
return accounts.map((x) => getAddress(x));
7474
},
7575
async getChainId() {
7676
const provider = await this.getProvider();
@@ -89,7 +89,6 @@ export function blocto({ appId }: BloctoParameters = {}) {
8989
};
9090

9191
walletProvider = new BloctoSDK({ ethereum, appId })?.ethereum;
92-
9392
if (!walletProvider) {
9493
throw new Error('Blocto SDK is not initialized.');
9594
}

adapters/web3-react-connector/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# @blocto/web3-react-connector
22

3+
## 1.0.7
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [bd6b11c]
8+
- Updated dependencies [74abbd7]
9+
- @blocto/sdk@0.10.0
10+
11+
## 1.0.7-beta.0
12+
13+
### Patch Changes
14+
15+
- Updated dependencies [74abbd7]
16+
- @blocto/sdk@0.10.0-beta.0
17+
318
## 1.0.6
419

520
### Patch Changes

adapters/web3-react-connector/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@blocto/web3-react-connector",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "A Blocto SDK connector for web3-react",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",
@@ -43,7 +43,7 @@
4343
"url": "git://github.com/portto/blocto-sdk.git"
4444
},
4545
"dependencies": {
46-
"@blocto/sdk": "^0.9.1",
46+
"@blocto/sdk": "^0.10.0",
4747
"@web3-react/types": "^8.1.2-beta.0"
4848
},
4949
"devDependencies": {

packages/blocto-sdk/CHANGELOG.md

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

3+
## 0.10.0
4+
5+
### Minor Changes
6+
7+
- bd6b11c: passing dApp's urlParams to login & authz Iframe
8+
- 74abbd7: Add L2 Blast & Blast Sepolia Testnet
9+
10+
## 0.10.0-beta.1
11+
12+
### Minor Changes
13+
14+
- bd6b11c: passing dApp's urlParams to login & authz Iframe
15+
16+
## 0.10.0-beta.0
17+
18+
### Minor Changes
19+
20+
- 74abbd7: Add L2 Blast & Blast Sepolia Testnet
21+
322
## 0.9.1
423

524
### Patch Changes

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.9.1",
3+
"version": "0.10.0",
44
"repository": "git@github.com:portto/blocto-sdk.git",
55
"author": "Chiaki.C",
66
"license": "MIT",

packages/blocto-sdk/src/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ export const ETH_RPC_LIST: Mapping = {
7777

7878
// zKatana Sepolia Testnet
7979
1261120: 'https://rpc.startale.com/zkatana',
80+
81+
// Blast
82+
81457: 'https://rpc.blast.io',
83+
// Blast Sepolia Testnet
84+
168587773: 'https://sepolia.blast.io'
8085
};
8186

8287
export const ETH_ENV_WALLET_SERVER_MAPPING: Mapping = {

packages/blocto-sdk/src/providers/ethereum.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ export default class EthereumProvider
689689
const params = new URLSearchParams();
690690
params.set('l6n', window.location.origin);
691691
params.set('v', SDK_VERSION);
692+
params.set('q', `${window.location.pathname}${window.location.search}`);
692693
const emailParam = email && isEmail(email) ? `/${email}` : '';
693694
const loginFrame = await this.setIframe(
694695
`/authn${emailParam}?${params.toString()}`
@@ -994,7 +995,15 @@ export default class EthereumProvider
994995
method: 'POST',
995996
body: JSON.stringify([params, revert]),
996997
});
997-
const authzFrame = await this.setIframe(`/authz/${authorizationId}`);
998+
const iframeParams = new URLSearchParams();
999+
iframeParams.set('l6n', window.location.origin);
1000+
iframeParams.set(
1001+
'q',
1002+
`${window.location.pathname}${window.location.search}`
1003+
);
1004+
const authzFrame = await this.setIframe(
1005+
`/authz/${authorizationId}?${iframeParams.toString()}`
1006+
);
9981007
return this.responseListener(authzFrame, 'txHash');
9991008
}
10001009

yarn.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,15 @@
11361136
resolved "https://registry.npmjs.org/@blakeembrey/template/-/template-1.1.0.tgz"
11371137
integrity sha512-iZf+UWfL+DogJVpd/xMQyP6X6McYd6ArdYoPMiv/zlOTzeXXfQbYxBNJJBF6tThvsjLMbA8tLjkCdm9RWMFCCw==
11381138

1139+
"@blocto/sdk@^0.9.1":
1140+
version "0.9.1"
1141+
resolved "https://registry.yarnpkg.com/@blocto/sdk/-/sdk-0.9.1.tgz#86eb3f972f6bdd78a1c929e271c652f8ec5e1bd0"
1142+
integrity sha512-JPBKDUrgTrTc9PaCj1iNleMy68V6DARa93sJa6OBvxkFCtYNxGn+sNCOZqhCU/3YjQ6z75/Mls2oF4kQe/04cw==
1143+
dependencies:
1144+
buffer "^6.0.3"
1145+
eip1193-provider "^1.0.1"
1146+
js-sha3 "^0.8.0"
1147+
11391148
"@blocto/wagmi-connector@npm:@blocto/wagmi-connector@^1.3.1":
11401149
version "1.3.1"
11411150
resolved "https://registry.yarnpkg.com/@blocto/wagmi-connector/-/wagmi-connector-1.3.1.tgz#513feec757e33c24e6e98c4bbb9f326b90d58325"

0 commit comments

Comments
 (0)