From 1ce5c0e23aac2b67976fc471c5c56d68f5b7962b Mon Sep 17 00:00:00 2001 From: Tomas Martykan Date: Thu, 6 Feb 2025 16:37:12 +0100 Subject: [PATCH] feat(suite-native): add walletconnect --- suite-native/app/package.json | 7 +++ suite-native/app/src/initActions.ts | 5 ++ suite-native/app/tsconfig.json | 3 + suite-native/state/package.json | 1 + suite-native/state/src/reducers.ts | 3 + suite-native/state/tsconfig.json | 3 + yarn.lock | 98 +++++++++++++++++++++++++++++ 7 files changed, 120 insertions(+) diff --git a/suite-native/app/package.json b/suite-native/app/package.json index dad471adb95..4ad09a14af6 100644 --- a/suite-native/app/package.json +++ b/suite-native/app/package.json @@ -23,6 +23,7 @@ "dependencies": { "@gorhom/bottom-sheet": "5.0.5", "@mobily/ts-belt": "^3.13.1", + "@react-native-async-storage/async-storage": "^2.1.1", "@react-native-community/netinfo": "^11.4.1", "@react-native/metro-config": "^0.76.1", "@react-navigation/bottom-tabs": "6.6.1", @@ -42,6 +43,7 @@ "@suite-common/token-definitions": "workspace:*", "@suite-common/wallet-core": "workspace:*", "@suite-common/wallet-types": "workspace:*", + "@suite-common/walletconnect": "workspace:*", "@suite-native/accounts": "workspace:*", "@suite-native/alerts": "workspace:*", "@suite-native/analytics": "workspace:*", @@ -83,6 +85,7 @@ "@trezor/styles": "workspace:*", "@trezor/theme": "workspace:*", "@trezor/trezor-user-env-link": "workspace:*", + "@walletconnect/react-native-compat": "^2.18.0", "@whatwg-node/events": "0.1.2", "abortcontroller-polyfill": "1.7.6", "buffer": "^6.0.3", @@ -104,6 +107,7 @@ "expo-system-ui": "^4.0.2", "expo-updates": "0.26.6", "expo-video": "^2.0.1", + "fast-text-encoding": "^1.0.6", "lottie-react-native": "^7.1.0", "node-libs-browser": "^2.2.1", "react": "18.2.0", @@ -111,6 +115,7 @@ "react-native": "0.76.1", "react-native-edge-to-edge": "^1.3.1", "react-native-gesture-handler": "^2.21.0", + "react-native-get-random-values": "^1.11.0", "react-native-keyboard-aware-scroll-view": "0.9.5", "react-native-mmkv": "2.12.2", "react-native-quick-crypto": "^0.7.6", @@ -132,8 +137,10 @@ "@react-native/babel-preset": "^0.75.2", "@suite-common/test-utils": "workspace:^", "@trezor/connect-mobile": "workspace:^", + "@types/fast-text-encoding": "^1", "@types/jest": "^29.5.12", "@types/node": "22.10.1", + "@types/react-native-get-random-values": "^1", "babel-plugin-transform-inline-environment-variables": "^0.4.4", "babel-plugin-transform-remove-console": "^6.9.4", "detox": "^20.25.6", diff --git a/suite-native/app/src/initActions.ts b/suite-native/app/src/initActions.ts index 8fefd6c7920..2c5e1d72775 100644 --- a/suite-native/app/src/initActions.ts +++ b/suite-native/app/src/initActions.ts @@ -9,6 +9,9 @@ import { initStakeDataThunk, periodicFetchFiatRatesThunk, } from '@suite-common/wallet-core'; +// WalletConnect and its polyfills for RN +import '@walletconnect/react-native-compat'; +import { walletConnectInitThunk } from '@suite-common/walletconnect'; import { initAnalyticsThunk } from '@suite-native/analytics'; import { selectFiatCurrencyCode } from '@suite-native/settings'; import { setIsAppReady, setIsConnectInitialized } from '@suite-native/state/src/appSlice'; @@ -47,6 +50,8 @@ export const applicationInit = createThunk( }), ); + dispatch(walletConnectInitThunk()); + // Create Portfolio Tracker device if it doesn't exist dispatch(createImportedDeviceThunk()); } catch (error) { diff --git a/suite-native/app/tsconfig.json b/suite-native/app/tsconfig.json index 087ce56a059..ecea01ad4e5 100644 --- a/suite-native/app/tsconfig.json +++ b/suite-native/app/tsconfig.json @@ -29,6 +29,9 @@ { "path": "../../suite-common/wallet-types" }, + { + "path": "../../suite-common/walletconnect" + }, { "path": "../accounts" }, { "path": "../alerts" }, { "path": "../analytics" }, diff --git a/suite-native/state/package.json b/suite-native/state/package.json index d8c1d1360d2..3fc4c626de7 100644 --- a/suite-native/state/package.json +++ b/suite-native/state/package.json @@ -21,6 +21,7 @@ "@suite-common/toast-notifications": "workspace:*", "@suite-common/token-definitions": "workspace:*", "@suite-common/wallet-core": "workspace:*", + "@suite-common/walletconnect": "workspace:*", "@suite-native/blockchain": "workspace:*", "@suite-native/device": "workspace:*", "@suite-native/device-authorization": "workspace:*", diff --git a/suite-native/state/src/reducers.ts b/suite-native/state/src/reducers.ts index 68f1d9db7b0..f20485d33f0 100644 --- a/suite-native/state/src/reducers.ts +++ b/suite-native/state/src/reducers.ts @@ -20,6 +20,7 @@ import { prepareStakeReducer, prepareTransactionsReducer, } from '@suite-common/wallet-core'; +import { prepareWalletConnectReducer } from '@suite-common/walletconnect'; import { deviceAuthorizationReducer } from '@suite-native/device-authorization'; import { DiscoveryConfigState, @@ -63,6 +64,7 @@ const sendFormReducer = sendFormSlice.prepareReducer(extraDependencies); const stakeReducer = prepareStakeReducer(extraDependencies); const firmwareReducer = prepareFirmwareReducer(extraDependencies); const connectPopupReducer = prepareConnectPopupReducer(extraDependencies); +const walletConnectReducer = prepareWalletConnectReducer(extraDependencies); export const prepareRootReducers = async () => { const appSettingsPersistedReducer = await preparePersistReducer({ @@ -85,6 +87,7 @@ export const prepareRootReducers = async () => { fees: feesReducer, stake: stakeReducer, connectPopup: connectPopupReducer, + walletConnect: walletConnectReducer, }); const walletPersistedReducer = await preparePersistReducer({ diff --git a/suite-native/state/tsconfig.json b/suite-native/state/tsconfig.json index 6554093272b..b12495f364c 100644 --- a/suite-native/state/tsconfig.json +++ b/suite-native/state/tsconfig.json @@ -25,6 +25,9 @@ { "path": "../../suite-common/wallet-core" }, + { + "path": "../../suite-common/walletconnect" + }, { "path": "../blockchain" }, { "path": "../device" }, { "path": "../device-authorization" }, diff --git a/yarn.lock b/yarn.lock index ab25110aada..68f8fa83271 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6885,6 +6885,17 @@ __metadata: languageName: node linkType: hard +"@react-native-async-storage/async-storage@npm:^2.1.1": + version: 2.1.1 + resolution: "@react-native-async-storage/async-storage@npm:2.1.1" + dependencies: + merge-options: "npm:^3.0.4" + peerDependencies: + react-native: ^0.0.0-0 || >=0.65 <1.0 + checksum: 10/ae65d10606e2ba307dc7a4362612c3568fdae3833dae407810c2f457ab1a6ec2c50f2979c8afbf6477b56c8033b8f332038c54e617165618d1b5305e91784300 + languageName: node + linkType: hard + "@react-native-community/cli-clean@npm:15.1.2": version: 15.1.2 resolution: "@react-native-community/cli-clean@npm:15.1.2" @@ -10537,6 +10548,7 @@ __metadata: "@gorhom/bottom-sheet": "npm:5.0.5" "@jest/globals": "npm:^29.7.0" "@mobily/ts-belt": "npm:^3.13.1" + "@react-native-async-storage/async-storage": "npm:^2.1.1" "@react-native-community/cli": "npm:^15.1.2" "@react-native-community/netinfo": "npm:^11.4.1" "@react-native/babel-preset": "npm:^0.75.2" @@ -10559,6 +10571,7 @@ __metadata: "@suite-common/token-definitions": "workspace:*" "@suite-common/wallet-core": "workspace:*" "@suite-common/wallet-types": "workspace:*" + "@suite-common/walletconnect": "workspace:*" "@suite-native/accounts": "workspace:*" "@suite-native/alerts": "workspace:*" "@suite-native/analytics": "workspace:*" @@ -10601,8 +10614,11 @@ __metadata: "@trezor/styles": "workspace:*" "@trezor/theme": "workspace:*" "@trezor/trezor-user-env-link": "workspace:*" + "@types/fast-text-encoding": "npm:^1" "@types/jest": "npm:^29.5.12" "@types/node": "npm:22.10.1" + "@types/react-native-get-random-values": "npm:^1" + "@walletconnect/react-native-compat": "npm:^2.18.0" "@whatwg-node/events": "npm:0.1.2" abortcontroller-polyfill: "npm:1.7.6" babel-plugin-transform-inline-environment-variables: "npm:^0.4.4" @@ -10628,6 +10644,7 @@ __metadata: expo-system-ui: "npm:^4.0.2" expo-updates: "npm:0.26.6" expo-video: "npm:^2.0.1" + fast-text-encoding: "npm:^1.0.6" jest: "npm:^29.7.0" jest-junit: "npm:^16.0.0" lottie-react-native: "npm:^7.1.0" @@ -10638,6 +10655,7 @@ __metadata: react-native: "npm:0.76.1" react-native-edge-to-edge: "npm:^1.3.1" react-native-gesture-handler: "npm:^2.21.0" + react-native-get-random-values: "npm:^1.11.0" react-native-keyboard-aware-scroll-view: "npm:0.9.5" react-native-mmkv: "npm:2.12.2" react-native-quick-crypto: "npm:^0.7.6" @@ -11707,6 +11725,7 @@ __metadata: "@suite-common/toast-notifications": "workspace:*" "@suite-common/token-definitions": "workspace:*" "@suite-common/wallet-core": "workspace:*" + "@suite-common/walletconnect": "workspace:*" "@suite-native/blockchain": "workspace:*" "@suite-native/device": "workspace:*" "@suite-native/device-authorization": "workspace:*" @@ -14078,6 +14097,13 @@ __metadata: languageName: node linkType: hard +"@types/fast-text-encoding@npm:^1": + version: 1.0.3 + resolution: "@types/fast-text-encoding@npm:1.0.3" + checksum: 10/34ec2bbaf3e3ee36b7b74375293becc735378f77e9cd93b810ad988b42991ee80d30fb942e6ba03adfc1f0cb0e2024a0aeee84475847563ed6782e21c4c0f5f0 + languageName: node + linkType: hard + "@types/file-saver@npm:^2.0.6": version: 2.0.7 resolution: "@types/file-saver@npm:2.0.7" @@ -14766,6 +14792,13 @@ __metadata: languageName: node linkType: hard +"@types/react-native-get-random-values@npm:^1": + version: 1.8.2 + resolution: "@types/react-native-get-random-values@npm:1.8.2" + checksum: 10/08f3f82efbb5b6d9acd8f7f55a2dac9f228886323ac3018a1bab46cd1b45f24809d194fd2a3fe02a9ec4196606325e5cfffde0b0057ae785208b658fdc83c821 + languageName: node + linkType: hard + "@types/react-qr-reader@npm:^2.1.7": version: 2.1.7 resolution: "@types/react-qr-reader@npm:2.1.7" @@ -15631,6 +15664,26 @@ __metadata: languageName: node linkType: hard +"@walletconnect/react-native-compat@npm:^2.18.0": + version: 2.18.0 + resolution: "@walletconnect/react-native-compat@npm:2.18.0" + dependencies: + events: "npm:3.3.0" + fast-text-encoding: "npm:1.0.6" + react-native-url-polyfill: "npm:2.0.0" + peerDependencies: + "@react-native-async-storage/async-storage": "*" + "@react-native-community/netinfo": "*" + expo-application: "*" + react-native: "*" + react-native-get-random-values: "*" + peerDependenciesMeta: + expo-application: + optional: true + checksum: 10/ef82bffb1f85f588b2f813ae30dbaf7ed87f37138548e5b3820e68df42f8a2c446d9c8a8a1f6c0fbd6d7a0c8ae89009aa02d75e208c7e58442433d2d93b97f2f + languageName: node + linkType: hard + "@walletconnect/relay-api@npm:1.0.11": version: 1.0.11 resolution: "@walletconnect/relay-api@npm:1.0.11" @@ -24538,6 +24591,13 @@ __metadata: languageName: node linkType: hard +"fast-base64-decode@npm:^1.0.0": + version: 1.0.0 + resolution: "fast-base64-decode@npm:1.0.0" + checksum: 10/4c59eb1775a7f132333f296c5082476fdcc8f58d023c42ed6d378d2e2da4c328c7a71562f271181a725dd17cdaa8f2805346cc330cdbad3b8e4b9751508bd0a3 + languageName: node + linkType: hard + "fast-copy@npm:^3.0.2": version: 3.0.2 resolution: "fast-copy@npm:3.0.2" @@ -24628,6 +24688,13 @@ __metadata: languageName: node linkType: hard +"fast-text-encoding@npm:1.0.6, fast-text-encoding@npm:^1.0.6": + version: 1.0.6 + resolution: "fast-text-encoding@npm:1.0.6" + checksum: 10/f7b9e2e7a21e4ae5f4b8d3729850be83fb45052b28c9c38c09b8366463a291d6dc5448359238bdaf87f6a9e907d5895a94319a2c5e0e9f0786859ad6312d1d06 + languageName: node + linkType: hard + "fast-uri@npm:^3.0.1": version: 3.0.1 resolution: "fast-uri@npm:3.0.1" @@ -31764,6 +31831,15 @@ __metadata: languageName: node linkType: hard +"merge-options@npm:^3.0.4": + version: 3.0.4 + resolution: "merge-options@npm:3.0.4" + dependencies: + is-plain-obj: "npm:^2.1.0" + checksum: 10/d86ddb3dd6e85d558dbf25dc944f3527b6bacb944db3fdda6e84a3f59c4e4b85231095f58b835758b9a57708342dee0f8de0dffa352974a48221487fe9f4584f + languageName: node + linkType: hard + "merge-source-map@npm:1.0.4": version: 1.0.4 resolution: "merge-source-map@npm:1.0.4" @@ -37352,6 +37428,17 @@ __metadata: languageName: node linkType: hard +"react-native-get-random-values@npm:^1.11.0": + version: 1.11.0 + resolution: "react-native-get-random-values@npm:1.11.0" + dependencies: + fast-base64-decode: "npm:^1.0.0" + peerDependencies: + react-native: ">=0.56" + checksum: 10/eb04833ce2b66309d737f1447ab01ad32aca00a8d1cc4de7b4e751c23f4d9f8059a2643bb16e0b6f3e6b074a9e57e769bb2bf2afc50a912c5661d80a6ce4de34 + languageName: node + linkType: hard + "react-native-iphone-x-helper@npm:^1.0.3": version: 1.3.1 resolution: "react-native-iphone-x-helper@npm:1.3.1" @@ -37481,6 +37568,17 @@ __metadata: languageName: node linkType: hard +"react-native-url-polyfill@npm:2.0.0": + version: 2.0.0 + resolution: "react-native-url-polyfill@npm:2.0.0" + dependencies: + whatwg-url-without-unicode: "npm:8.0.0-3" + peerDependencies: + react-native: "*" + checksum: 10/6a8d605eeb1b0ee9b0f47f1866acc2edfa2131a4a8fb1ea3839ceb507e225b894ed66f49a3bd826fc964f2c8005b3678c9d3b65d07eb0a3b979be830cb618686 + languageName: node + linkType: hard + "react-native@npm:0.76.1": version: 0.76.1 resolution: "react-native@npm:0.76.1"