Skip to content

Commit bb35715

Browse files
committed
feat(suite): minimal walletconnect implementation for evm
1 parent 995410a commit bb35715

File tree

13 files changed

+2040
-43
lines changed

13 files changed

+2040
-43
lines changed

packages/suite-desktop-connect-popup/src/connectPopupThunks.ts

+23-23
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,22 @@ import { serializeError } from '@trezor/connect/src/constants/errors';
77

88
const CONNECT_POPUP_MODULE = '@common/connect-popup';
99

10-
export const connectPopupCallThunk = createThunk(
10+
export const connectPopupCallThunk = createThunk<
11+
Promise<{
12+
id: number;
13+
success: boolean;
14+
payload: any;
15+
}>,
16+
{
17+
id: number;
18+
method: string;
19+
payload: any;
20+
processName?: string;
21+
origin?: string;
22+
}
23+
>(
1124
`${CONNECT_POPUP_MODULE}/callThunk`,
12-
async (
13-
{
14-
id,
15-
method,
16-
payload,
17-
processName,
18-
origin,
19-
}: {
20-
id: number;
21-
method: string;
22-
payload: any;
23-
processName?: string;
24-
origin?: string;
25-
},
26-
{ dispatch, getState, extra },
27-
) => {
25+
async ({ id, method, payload, processName, origin }, { dispatch, getState, extra }) => {
2826
try {
2927
const device = selectSelectedDevice(getState());
3028

@@ -71,17 +69,18 @@ export const connectPopupCallThunk = createThunk(
7169

7270
dispatch(extra.actions.onModalCancel());
7371

74-
desktopApi.connectPopupResponse({
72+
return {
7573
...response,
7674
id,
77-
});
75+
};
7876
} catch (error) {
7977
console.error('connectPopupCallThunk', error);
80-
desktopApi.connectPopupResponse({
78+
79+
return {
8180
success: false,
8281
payload: serializeError(error),
8382
id,
84-
});
83+
};
8584
}
8685
},
8786
);
@@ -90,8 +89,9 @@ export const connectPopupInitThunk = createThunk(
9089
`${CONNECT_POPUP_MODULE}/initPopupThunk`,
9190
async (_, { dispatch }) => {
9291
if (desktopApi.available && (await desktopApi.connectPopupEnabled())) {
93-
desktopApi.on('connect-popup/call', params => {
94-
dispatch(connectPopupCallThunk(params));
92+
desktopApi.on('connect-popup/call', async params => {
93+
const response = await dispatch(connectPopupCallThunk(params)).unwrap();
94+
desktopApi.connectPopupResponse(response);
9595
});
9696
desktopApi.connectPopupReady();
9797
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "@trezor/suite-walletconnect",
3+
"version": "1.0.0",
4+
"private": true,
5+
"license": "See LICENSE.md in repo root",
6+
"sideEffects": false,
7+
"main": "src/index",
8+
"scripts": {
9+
"depcheck": "yarn g:depcheck",
10+
"type-check": "yarn g:tsc --build",
11+
"test:unit": "yarn g:jest -c ../../jest.config.base.js",
12+
"test-unit:watch": "yarn g:jest -c ../../jest.config.base.js -o --watch"
13+
},
14+
"dependencies": {
15+
"@reduxjs/toolkit": "1.9.5",
16+
"@reown/walletkit": "^1.1.1",
17+
"@suite-common/redux-utils": "workspace:*",
18+
"@suite-common/suite-types": "workspace:*",
19+
"@trezor/connect": "workspace:*",
20+
"@walletconnect/core": "^2.17.2",
21+
"@walletconnect/utils": "^2.17.2"
22+
},
23+
"devDependencies": {
24+
"redux-thunk": "^2.4.2"
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './walletConnectThunks';
2+
export * from './walletConnectMiddleware';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { accountsActions } from '@suite-common/wallet-core';
2+
import { createMiddlewareWithExtraDeps } from '@suite-common/redux-utils';
3+
4+
import * as walletConnectActions from './walletConnectThunks';
5+
6+
export const prepareWalletConnectMiddleware = createMiddlewareWithExtraDeps(
7+
async (action, { dispatch, next }) => {
8+
await next(action);
9+
10+
if (accountsActions.updateSelectedAccount.match(action) && action.payload.account) {
11+
dispatch(
12+
walletConnectActions.switchSelectedAccountThunk({
13+
account: action.payload.account,
14+
}),
15+
);
16+
}
17+
18+
if (
19+
accountsActions.createAccount.match(action) ||
20+
accountsActions.removeAccount.match(action)
21+
) {
22+
dispatch(walletConnectActions.updateAccountsThunk());
23+
}
24+
25+
return action;
26+
},
27+
);

0 commit comments

Comments
 (0)