Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
martykan committed Dec 6, 2024
1 parent 370c46e commit 1eb19e8
Show file tree
Hide file tree
Showing 7 changed files with 1,580 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/suite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@suite-common/wallet-core": "workspace:*",
"@suite-common/wallet-types": "workspace:*",
"@suite-common/wallet-utils": "workspace:*",
"@suite-common/walletconnect": "workspace:*",
"@trezor/address-validator": "workspace:*",
"@trezor/analytics": "workspace:*",
"@trezor/blockchain-link": "workspace:*",
Expand Down
3 changes: 3 additions & 0 deletions packages/suite/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
{
"path": "../../suite-common/wallet-utils"
},
{
"path": "../../suite-common/walletconnect"
},
{ "path": "../address-validator" },
{ "path": "../analytics" },
{ "path": "../blockchain-link" },
Expand Down
25 changes: 25 additions & 0 deletions suite-common/walletconnect/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@suite-common/walletconnect",
"version": "1.0.0",
"private": true,
"license": "See LICENSE.md in repo root",
"sideEffects": false,
"main": "src/index",
"scripts": {
"depcheck": "yarn g:depcheck",
"type-check": "yarn g:tsc --build",
"test:unit": "yarn g:jest -c ../../jest.config.base.js",
"test-unit:watch": "yarn g:jest -c ../../jest.config.base.js -o --watch"
},
"dependencies": {
"@reduxjs/toolkit": "1.9.5",
"@reown/walletkit": "^1.1.1",
"@suite-common/redux-utils": "workspace:*",
"@suite-common/suite-types": "workspace:*",
"@walletconnect/core": "^2.17.2",
"@walletconnect/utils": "^2.17.2"
},
"devDependencies": {
"redux-thunk": "^2.4.2"
}
}
1 change: 1 addition & 0 deletions suite-common/walletconnect/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './walletConnectThunks';
80 changes: 80 additions & 0 deletions suite-common/walletconnect/src/walletConnectThunks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { Core } from '@walletconnect/core';
import { WalletKit } from '@reown/walletkit';
import { buildApprovedNamespaces, getSdkError } from '@walletconnect/utils';
import { WalletKit as WalletKitClient } from '@reown/walletkit/dist/types/client';

import { createThunk } from '@suite-common/redux-utils';

const WALLETCONNECT_MODULE = '@common/walletconnect';

const PROJECT_ID = '203549d0480d0f24d994780f34889b03';

let walletKit: WalletKitClient;

export const walletConnectInitThunk = createThunk(
`${WALLETCONNECT_MODULE}/walletConnectInitThunk`,
async (_, { dispatch }) => {
const core = new Core({
projectId: PROJECT_ID,
});

const metadata = {
name: 'Trezor Suite',
description: 'Manage your Trezor device',
url: 'https://suite.trezor.io',
icons: ['https://assets.reown.com/reown-profile-pic.png'],
};

walletKit = await WalletKit.init({
core,
metadata,
});
walletKit.on('session_proposal', async event => {
try {
const approvedNamespaces = buildApprovedNamespaces({
proposal: event.params,
supportedNamespaces: {
eip155: {
// TODO get enabled chains
chains: ['eip155:1', 'eip155:137'],
// TODO methods
methods: ['eth_sendTransaction', 'personal_sign'],
events: ['accountsChanged', 'chainChanged'],
accounts: [
// TODO get current accounts
'eip155:1:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb',
'eip155:137:0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb',
],
},
},
});

const session = await walletKit.approveSession({
id: event.id,
namespaces: approvedNamespaces,
});

console.log(session);

Check failure on line 57 in suite-common/walletconnect/src/walletConnectThunks.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement
} catch (error) {
console.error(error);

await walletKit.rejectSession({
id: event.id,
reason: getSdkError('USER_REJECTED'),
});
}
});

walletKit.on('session_request', async event => {

Check failure on line 68 in suite-common/walletconnect/src/walletConnectThunks.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Async arrow function has no 'await' expression
console.log(event);

Check failure on line 69 in suite-common/walletconnect/src/walletConnectThunks.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement
});
},
);

export const walletConnectPairThunk = createThunk<void, { uri: string }>(
`${WALLETCONNECT_MODULE}/walletConnectPairThunk`,
async ({ uri }, { dispatch }) => {
const session = await walletKit.pair({ uri });
console.log(session);

Check failure on line 78 in suite-common/walletconnect/src/walletConnectThunks.ts

View workflow job for this annotation

GitHub Actions / Linting and formatting

Unexpected console statement
},
);
9 changes: 9 additions & 0 deletions suite-common/walletconnect/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": { "outDir": "libDev" },
"include": [".", "**/*.json"],
"references": [
{ "path": "../redux-utils" },
{ "path": "../suite-types" }
]
}
Loading

0 comments on commit 1eb19e8

Please sign in to comment.