-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,580 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './walletConnectThunks'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} catch (error) { | ||
console.error(error); | ||
|
||
await walletKit.rejectSession({ | ||
id: event.id, | ||
reason: getSdkError('USER_REJECTED'), | ||
}); | ||
} | ||
}); | ||
|
||
walletKit.on('session_request', async event => { | ||
console.log(event); | ||
}); | ||
}, | ||
); | ||
|
||
export const walletConnectPairThunk = createThunk<void, { uri: string }>( | ||
`${WALLETCONNECT_MODULE}/walletConnectPairThunk`, | ||
async ({ uri }, { dispatch }) => { | ||
const session = await walletKit.pair({ uri }); | ||
console.log(session); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } | ||
] | ||
} |
Oops, something went wrong.