Skip to content

Commit 98062f9

Browse files
committed
feat(wallets): coinbasewallet sdk
1 parent 28fb4ea commit 98062f9

File tree

16 files changed

+1751
-660
lines changed

16 files changed

+1751
-660
lines changed

DISCO3.md

Lines changed: 401 additions & 352 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
> a performant web3 react library
66
7-
87
> [Read the Disco3 Design and Arch. Document](https://github.com/manifoldfinance/disco3-react/blob/master/DISCO3.md)
8+
99
---
1010

11-
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/5693/badge)](https://bestpractices.coreinfrastructure.org/projects/5693) [![manifoldfinance.eth](https://img.shields.io/static/v1?label=&message=manifoldfinance.eth&color=black&logo=ethereum&logoColor=white)](https://etherscan.io/enslookup-search?search=manifoldfinance.eth) [![manifoldfinance - disco3-react](https://img.shields.io/static/v1?label=manifoldfinance&message=disco3-react&color=black&logo=github)](https://github.com/manifoldfinance/disco3-react 'Go to GitHub repo')
11+
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/5693/badge)](https://bestpractices.coreinfrastructure.org/projects/5693)
12+
[![manifoldfinance.eth](https://img.shields.io/static/v1?label=&message=manifoldfinance.eth&color=black&logo=ethereum&logoColor=white)](https://etherscan.io/enslookup-search?search=manifoldfinance.eth)
13+
[![manifoldfinance - disco3-react](https://img.shields.io/static/v1?label=manifoldfinance&message=disco3-react&color=black&logo=github)](https://github.com/manifoldfinance/disco3-react 'Go to GitHub repo')
1214

1315
| package | description |
1416
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

packages/network/src/index.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Actions, Web3ReactStore } from '@disco3/types';
33
import { MockEip1193Bridge } from '../../url/src/index.spec';
44
import { Network } from './';
55
import { createWeb3ReactStoreAndActions } from '@disco3/store';
6+
67
jest.mock('@ethersproject/providers', () => ({
78
JsonRpcProvider: class MockJsonRpcProvider {
89
getSigner() {}

packages/store/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"start": "tsc --watch"
4242
},
4343
"dependencies": {
44-
"@disco3/types": "8.0.2-beta.0",
44+
"@disco3/types": "^8.0.2-beta.1",
4545
"@ethersproject/address": "^5.4.0",
4646
"zustand": "^4.0.0-beta.0"
4747
}

packages/store/src/index.spec.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { ChainIdNotAllowedError, createWeb3ReactStoreAndActions } from '.';
1+
import {
2+
ChainIdNotAllowedError,
3+
MAX_SAFE_CHAIN_ID,
4+
createWeb3ReactStoreAndActions,
5+
} from '.';
26

37
test('ChainIdNotAllowedError', () => {
48
const error = new ChainIdNotAllowedError(1, [2]);
@@ -25,7 +29,7 @@ describe('#createWeb3ReactStoreAndActions', () => {
2529
});
2630

2731
describe('#startActivation', () => {
28-
test('#works', () => {
32+
test('works', () => {
2933
const [store, actions] = createWeb3ReactStoreAndActions();
3034
actions.startActivation();
3135
expect(store.getState()).toEqual({
@@ -35,6 +39,7 @@ describe('#createWeb3ReactStoreAndActions', () => {
3539
error: undefined,
3640
});
3741
});
42+
3843
test('cancellation works', () => {
3944
const [store, actions] = createWeb3ReactStoreAndActions();
4045
const cancelActivation = actions.startActivation();
@@ -53,7 +58,7 @@ describe('#createWeb3ReactStoreAndActions', () => {
5358
describe('#update', () => {
5459
test('throws on bad chainIds', () => {
5560
const [, actions] = createWeb3ReactStoreAndActions();
56-
for (const chainId of [1.1, 0, Number.MAX_SAFE_INTEGER + 1]) {
61+
for (const chainId of [1.1, 0, MAX_SAFE_CHAIN_ID + 1]) {
5762
expect(() => actions.update({ chainId })).toThrow(
5863
`Invalid chainId ${chainId}`,
5964
);
@@ -196,15 +201,29 @@ describe('#createWeb3ReactStoreAndActions', () => {
196201
});
197202
});
198203

199-
test('#reportError', () => {
200-
const [store, actions] = createWeb3ReactStoreAndActions();
201-
const error = new Error();
202-
actions.reportError(error);
203-
expect(store.getState()).toEqual({
204-
chainId: undefined,
205-
accounts: undefined,
206-
activating: false,
207-
error,
204+
describe('#reportError', () => {
205+
test('sets error', () => {
206+
const [store, actions] = createWeb3ReactStoreAndActions();
207+
const error = new Error();
208+
actions.reportError(error);
209+
expect(store.getState()).toEqual({
210+
chainId: undefined,
211+
accounts: undefined,
212+
activating: false,
213+
error,
214+
});
215+
});
216+
217+
test('resets state', () => {
218+
const [store, actions] = createWeb3ReactStoreAndActions();
219+
actions.reportError(new Error());
220+
actions.reportError(undefined);
221+
expect(store.getState()).toEqual({
222+
chainId: undefined,
223+
accounts: undefined,
224+
activating: false,
225+
error: undefined,
226+
});
208227
});
209228
});
210229
});

packages/store/src/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
import { getAddress } from '@ethersproject/address';
21
import type {
32
Actions,
43
Web3ReactState,
54
Web3ReactStateUpdate,
65
Web3ReactStore,
76
} from '@disco3/types';
7+
88
import create from 'zustand/vanilla';
9+
import { getAddress } from '@ethersproject/address';
10+
11+
/**
12+
* MAX_SAFE_CHAIN_ID is the upper bound limit on what will be accepted for `chainId`
13+
* `MAX_SAFE_CHAIN_ID = floor( ( 2**53 - 39 ) / 2 ) = 4503599627370476`
14+
*
15+
* @see {@link https://github.com/MetaMask/metamask-extension/blob/b6673731e2367e119a5fee9a454dd40bd4968948/shared/constants/network.js#L31}
16+
*/
17+
export const MAX_SAFE_CHAIN_ID = 4503599627370476;
918

1019
function validateChainId(chainId: number): void {
1120
if (
1221
!Number.isInteger(chainId) ||
1322
chainId <= 0 ||
14-
chainId > Number.MAX_SAFE_INTEGER
23+
chainId > MAX_SAFE_CHAIN_ID
1524
) {
1625
throw new Error(`Invalid chainId ${chainId}`);
1726
}
@@ -73,9 +82,7 @@ export function createWeb3ReactStoreAndActions(
7382

7483
// return a function that cancels the activation iff nothing else has happened
7584
return () => {
76-
if (nullifier === nullifierCached) {
77-
store.setState({ ...DEFAULT_STATE, activating: false });
78-
}
85+
if (nullifier === nullifierCached) store.setState({ activating: false });
7986
};
8087
}
8188

packages/types/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"publishConfig": {
77
"access": "public"
88
},
9-
"version": "8.0.2-beta.0",
9+
"version": "8.0.2-beta.1",
1010
"type": "module",
1111
"files": [
1212
"dist/*"
@@ -25,6 +25,6 @@
2525
"start": "tsc --watch"
2626
},
2727
"dependencies": {
28-
"zustand": "^4.0.0-beta.0"
28+
"zustand": "^4.0.0-beta.2"
2929
}
3030
}

packages/types/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @version 0.0.18
3+
*/
4+
15
import type { State, StoreApi } from 'zustand/vanilla';
26

37
import type { EventEmitter } from 'node:events';
@@ -88,6 +92,11 @@ export abstract class Connector {
8892
this.actions = actions;
8993
}
9094

95+
/**
96+
* Attempt to initiate a connection, failing silently
97+
*/
98+
public connectEagerly?(...args: unknown[]): Promise<void> | void;
99+
91100
/**
92101
* Initiate a connection.
93102
*/

packages/types/yarn.lock

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/walletconnect/src/index.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import { createWeb3ReactStoreAndActions } from '@disco3/store';
21
import type { Actions, RequestArguments, Web3ReactStore } from '@disco3/types';
3-
import { WalletConnect } from '.';
2+
43
import { MockEIP1193Provider } from '../../eip1193/src/index.spec';
4+
import { WalletConnect } from '.';
5+
import { createWeb3ReactStoreAndActions } from '@disco3/store';
56

67
// necessary because walletconnect returns chainId as a number
7-
export class MockMockWalletConnectProvider extends MockEIP1193Provider {
8+
class MockMockWalletConnectProvider extends MockEIP1193Provider {
9+
public connector = new EventEmitter();
10+
811
public eth_chainId_number = jest.fn((chainId?: string) =>
912
chainId === undefined ? chainId : Number.parseInt(chainId, 16),
1013
);
@@ -35,7 +38,7 @@ describe('WalletConnect', () => {
3538
beforeEach(() => {
3639
let actions: Actions;
3740
[store, actions] = createWeb3ReactStoreAndActions();
38-
connector = new WalletConnect(actions, {});
41+
connector = new WalletConnect(actions, { rpc: {} }, true);
3942
});
4043

4144
beforeEach(async () => {

0 commit comments

Comments
 (0)