From 889fe3f5b8dcd92ea24eda07fb6398daa9b02efd Mon Sep 17 00:00:00 2001 From: Davide Segullo Date: Wed, 15 Jun 2022 13:24:47 +0200 Subject: [PATCH 01/10] feat: :sparkles: add wallet connect --- package.json | 4 + src/components/BalanceSummary.vue | 2 +- src/layouts/MainLayout.vue | 5 +- src/models/index.ts | 1 + src/models/session.ts | 1 + src/models/wallet-connect.ts | 18 + .../authentication/views/LoginHome.vue | 30 +- src/services/index.ts | 1 + src/services/wallet-connect.ts | 59 +++ src/signing/transaction-manager.ts | 37 ++ src/store/data/actions.ts | 63 ++- yarn.lock | 378 +++++++++++++++++- 12 files changed, 562 insertions(+), 37 deletions(-) create mode 100644 src/models/wallet-connect.ts create mode 100644 src/services/wallet-connect.ts diff --git a/package.json b/package.json index 185b0569..d7c4b577 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,9 @@ "@ledgerhq/hw-transport-webhid": "^6.20.0", "@ledgerhq/hw-transport-webusb": "^6.20.0", "@quasar/extras": "^1.0.0", + "@walletconnect/browser-utils": "^1.7.8", + "@walletconnect/client": "^1.7.8", + "@walletconnect/qrcode-modal": "^1.7.8", "axios": "^0.21.1", "bech32": "^2.0.0", "bignumber.js": "^9.0.2", @@ -54,6 +57,7 @@ "@types/w3c-web-hid": "^1.0.2", "@typescript-eslint/eslint-plugin": "^4.16.1", "@typescript-eslint/parser": "^4.16.1", + "@walletconnect/types": "^1.7.8", "eslint": "^7.14.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-import": "^2.19.1", diff --git a/src/components/BalanceSummary.vue b/src/components/BalanceSummary.vue index 45ad434a..30e72eb9 100644 --- a/src/components/BalanceSummary.vue +++ b/src/components/BalanceSummary.vue @@ -41,7 +41,7 @@ - + SEND diff --git a/src/layouts/MainLayout.vue b/src/layouts/MainLayout.vue index eccce333..1eb5de8e 100644 --- a/src/layouts/MainLayout.vue +++ b/src/layouts/MainLayout.vue @@ -91,6 +91,7 @@ import { useRouter } from 'vue-router'; import MenuLink from 'src/components/MenuLink.vue'; import FaucetDialog from 'src/components/FaucetDialog.vue'; +import { SessionType } from 'src/models'; export default defineComponent({ name: 'MainLayout', @@ -123,7 +124,9 @@ export default defineComponent({ }); window.addEventListener('keplr_keystorechange', async () => { - await store.dispatch('authentication/init'); + if (session.value && session.value.sessionType === SessionType.KEPLR) { + await store.dispatch('authentication/init'); + } }); onMounted(() => { diff --git a/src/models/index.ts b/src/models/index.ts index b18c3d3b..8cb0a34b 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -21,3 +21,4 @@ export * from './supply'; export * from './inflaction'; export * from './faucet'; export * from './fantoken'; +export * from './wallet-connect'; diff --git a/src/models/session.ts b/src/models/session.ts index a179d28e..ad7a78ad 100644 --- a/src/models/session.ts +++ b/src/models/session.ts @@ -2,6 +2,7 @@ export enum SessionType { KEPLR = 'keplr', LOCAL = 'local', LEDGER = 'ledger', + WALLET_CONNECT = 'walletconnect', EXTENSION = 'extension', EXPLORE = 'explore' } diff --git a/src/models/wallet-connect.ts b/src/models/wallet-connect.ts new file mode 100644 index 00000000..c4dfb429 --- /dev/null +++ b/src/models/wallet-connect.ts @@ -0,0 +1,18 @@ +export interface PeerMeta { + description: string + icons: string[] + name: string + url: string +} + +export interface WalletConnectPayload { + event: string + params: T[] +} + +export interface WalletConnectionParam { + accounts: string[] + chainId: number + peerId: string + peerMeta: PeerMeta +} diff --git a/src/modules/authentication/views/LoginHome.vue b/src/modules/authentication/views/LoginHome.vue index fd9e4f0c..44735d70 100644 --- a/src/modules/authentication/views/LoginHome.vue +++ b/src/modules/authentication/views/LoginHome.vue @@ -7,16 +7,8 @@ - - - - + +