From fd5521369ea160784cf7762ffba3e5890b7bd1b0 Mon Sep 17 00:00:00 2001 From: Kenny Joseph Date: Wed, 24 Jul 2024 16:39:58 -0400 Subject: [PATCH 1/3] add taproot support --- src/navigation/wallet/screens/AddWallet.tsx | 44 +++++++++++++++---- .../wallet/screens/WalletDetails.tsx | 10 ++++- src/store/wallet/effects/create/create.ts | 3 ++ src/store/wallet/utils/currency.ts | 4 ++ src/store/wallet/utils/wallet.ts | 8 ++++ 5 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/navigation/wallet/screens/AddWallet.tsx b/src/navigation/wallet/screens/AddWallet.tsx index 1d592eb0b..078219309 100644 --- a/src/navigation/wallet/screens/AddWallet.tsx +++ b/src/navigation/wallet/screens/AddWallet.tsx @@ -96,7 +96,11 @@ import InfoSvg from '../../../../assets/img/info.svg'; import {URL} from '../../../constants'; import {useTranslation} from 'react-i18next'; import {BitpayIdScreens} from '../../bitpay-id/BitpayIdGroup'; -import {IsERCToken, IsSegwitCoin} from '../../../store/wallet/utils/currency'; +import { + IsERCToken, + IsSegwitCoin, + IsTaprootCoin, +} from '../../../store/wallet/utils/currency'; import {updatePortfolioBalance} from '../../../store/wallet/wallet.actions'; import {LogActions} from '../../../store/log'; import {CommonActions, useTheme} from '@react-navigation/native'; @@ -272,7 +276,9 @@ const AddWallet = ({ BitpaySupportedCoins[currencyAbbreviation?.toLowerCase() as string] ?.properties?.singleAddress; const nativeSegwitCurrency = IsSegwitCoin(_currencyAbbreviation); + const taprootCurrency = IsTaprootCoin(_currencyAbbreviation); const [useNativeSegwit, setUseNativeSegwit] = useState(nativeSegwitCurrency); + const [useTaproot, setUseTaproot] = useState(false); const [evmWallets, setEvmWallets] = useState(); const [accountsInfo, setAccountsInfo] = useState< {receiveAddress: string; accountNumber: number}[] @@ -323,6 +329,16 @@ const AddWallet = ({ }); }, [navigation, t]); + const toggleUseNativeSegwit = () => { + setUseNativeSegwit(!useNativeSegwit); + setUseTaproot(false); + }; + + const toggleUseTaproot = () => { + setUseTaproot(!useTaproot); + setUseNativeSegwit(false); + }; + const addAssociatedWallet = async () => { try { const evmCoinOption = SupportedCoinsOptions.find( @@ -543,6 +559,7 @@ const AddWallet = ({ ? Network.regtest : network, useNativeSegwit, + useTaproot, singleAddress, walletName, ...(account !== undefined && { @@ -929,19 +946,30 @@ const AddWallet = ({ {showOptions && nativeSegwitCurrency && ( - { - setUseNativeSegwit(!useNativeSegwit); - }}> + toggleUseNativeSegwit()}> Segwit { - setUseNativeSegwit(!useNativeSegwit); - }} + onPress={() => toggleUseNativeSegwit()} + /> + + + + )} + + {showOptions && taprootCurrency && ( + + toggleUseTaproot()}> + + Taproot + + + toggleUseTaproot()} /> diff --git a/src/navigation/wallet/screens/WalletDetails.tsx b/src/navigation/wallet/screens/WalletDetails.tsx index 680aa6a1f..f5bc986ac 100644 --- a/src/navigation/wallet/screens/WalletDetails.tsx +++ b/src/navigation/wallet/screens/WalletDetails.tsx @@ -41,7 +41,11 @@ import { toggleHideAllBalances, } from '../../../store/app/app.actions'; import {startUpdateWalletStatus} from '../../../store/wallet/effects/status/status'; -import {findWalletById, isSegwit} from '../../../store/wallet/utils/wallet'; +import { + findWalletById, + isSegwit, + isTaproot, +} from '../../../store/wallet/utils/wallet'; import { setWalletScanning, updatePortfolioBalance, @@ -281,6 +285,10 @@ const getWalletType = ( if (isSegwit(addressType)) { return {title: 'Segwit'}; } + + if (isTaproot(addressType)) { + return {title: 'Taproot'}; + } return; }; diff --git a/src/store/wallet/effects/create/create.ts b/src/store/wallet/effects/create/create.ts index f49fce888..79b9b4ed3 100644 --- a/src/store/wallet/effects/create/create.ts +++ b/src/store/wallet/effects/create/create.ts @@ -38,6 +38,7 @@ export interface CreateOptions { account?: number; customAccount?: boolean; useNativeSegwit?: boolean; + useTaproot?: boolean; singleAddress?: boolean; walletName?: string; password?: string; @@ -374,6 +375,7 @@ const createWallet = password, singleAddress, useNativeSegwit, + useTaproot, } = { ...DEFAULT_CREATION_OPTIONS, ...options, @@ -402,6 +404,7 @@ const createWallet = coin, chain, useNativeSegwit, + useTaproot, }, (err: any) => { if (err) { diff --git a/src/store/wallet/utils/currency.ts b/src/store/wallet/utils/currency.ts index 0f35e3cd3..1a545b341 100644 --- a/src/store/wallet/utils/currency.ts +++ b/src/store/wallet/utils/currency.ts @@ -58,6 +58,10 @@ export const IsSegwitCoin = (currencyAbbreviation: string = ''): boolean => { return ['btc', 'ltc'].includes(currencyAbbreviation.toLowerCase()); }; +export const IsTaprootCoin = (currencyAbbreviation: string = ''): boolean => { + return ['btc'].includes(currencyAbbreviation.toLowerCase()); +}; + export const IsUtxoCoin = (currencyAbbreviation: string): boolean => { return Object.keys(BitpaySupportedUtxoCoins).includes( currencyAbbreviation.toLowerCase(), diff --git a/src/store/wallet/utils/wallet.ts b/src/store/wallet/utils/wallet.ts index 45bb6b26b..319553ea4 100644 --- a/src/store/wallet/utils/wallet.ts +++ b/src/store/wallet/utils/wallet.ts @@ -387,6 +387,14 @@ export const isSegwit = (addressType: string): boolean => { return addressType === 'P2WPKH' || addressType === 'P2WSH'; }; +export const isTaproot = (addressType: string): boolean => { + if (!addressType) { + return false; + } + + return addressType === 'P2TR'; +}; + export const GetProtocolPrefixAddress = ( currencyAbbreviation: string, From 132f7c3083441fe501b7f21268dee0bac1f6fc5a Mon Sep 17 00:00:00 2001 From: Kenny Joseph Date: Wed, 31 Jul 2024 14:59:37 -0400 Subject: [PATCH 2/3] change useTaproot to segwitVersion --- src/navigation/wallet/screens/AddWallet.tsx | 16 ++++++++-------- src/store/wallet/effects/create/create.ts | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/navigation/wallet/screens/AddWallet.tsx b/src/navigation/wallet/screens/AddWallet.tsx index 078219309..b7db6d86e 100644 --- a/src/navigation/wallet/screens/AddWallet.tsx +++ b/src/navigation/wallet/screens/AddWallet.tsx @@ -278,7 +278,7 @@ const AddWallet = ({ const nativeSegwitCurrency = IsSegwitCoin(_currencyAbbreviation); const taprootCurrency = IsTaprootCoin(_currencyAbbreviation); const [useNativeSegwit, setUseNativeSegwit] = useState(nativeSegwitCurrency); - const [useTaproot, setUseTaproot] = useState(false); + const [segwitVersion, setSegwitVersion] = useState(0); const [evmWallets, setEvmWallets] = useState(); const [accountsInfo, setAccountsInfo] = useState< {receiveAddress: string; accountNumber: number}[] @@ -330,13 +330,13 @@ const AddWallet = ({ }, [navigation, t]); const toggleUseNativeSegwit = () => { - setUseNativeSegwit(!useNativeSegwit); - setUseTaproot(false); + setUseNativeSegwit(!(useNativeSegwit && segwitVersion === 0)); + setSegwitVersion(0); }; const toggleUseTaproot = () => { - setUseTaproot(!useTaproot); - setUseNativeSegwit(false); + setUseNativeSegwit(!(useNativeSegwit && segwitVersion === 1)); + setSegwitVersion(1); }; const addAssociatedWallet = async () => { @@ -559,7 +559,7 @@ const AddWallet = ({ ? Network.regtest : network, useNativeSegwit, - useTaproot, + segwitVersion, singleAddress, walletName, ...(account !== undefined && { @@ -952,7 +952,7 @@ const AddWallet = ({ toggleUseNativeSegwit()} /> @@ -968,7 +968,7 @@ const AddWallet = ({ toggleUseTaproot()} /> diff --git a/src/store/wallet/effects/create/create.ts b/src/store/wallet/effects/create/create.ts index 79b9b4ed3..f0eb7249c 100644 --- a/src/store/wallet/effects/create/create.ts +++ b/src/store/wallet/effects/create/create.ts @@ -38,7 +38,7 @@ export interface CreateOptions { account?: number; customAccount?: boolean; useNativeSegwit?: boolean; - useTaproot?: boolean; + segwitVersion?: number; singleAddress?: boolean; walletName?: string; password?: string; @@ -375,7 +375,7 @@ const createWallet = password, singleAddress, useNativeSegwit, - useTaproot, + segwitVersion, } = { ...DEFAULT_CREATION_OPTIONS, ...options, @@ -404,7 +404,7 @@ const createWallet = coin, chain, useNativeSegwit, - useTaproot, + segwitVersion, }, (err: any) => { if (err) { From 34c438e1f2d3eff1e868d385945eb0146c7b3997 Mon Sep 17 00:00:00 2001 From: Kenny Joseph Date: Wed, 28 Aug 2024 16:22:51 -0400 Subject: [PATCH 3/3] bump bitcore to 10.3.0 --- package.json | 2 +- yarn.lock | 40 ++++++++++++++++++++-------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 8b8a716da..9e4ba4eaf 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "babel-plugin-module-resolver": "4.1.0", "big-integer": "1.6.51", "bitauth": "0.4.1", - "bitcore-wallet-client": "10.2.1", + "bitcore-wallet-client": "10.3.0", "buffer": "4.9.2", "countries-list": "2.6.1", "eth-sig-util": "3.0.1", diff --git a/yarn.lock b/yarn.lock index 21de0cb15..978e1942d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5784,10 +5784,10 @@ bitcore-lib-ltc@^10.0.36: lodash "^4.17.20" scryptsy "2.1.0" -bitcore-lib@^10.2.1: - version "10.2.1" - resolved "https://registry.yarnpkg.com/bitcore-lib/-/bitcore-lib-10.2.1.tgz#34c6d69901100e304f372c3eb1a2251c256b7e5c" - integrity sha512-GM2j+01vZK17GBbOe3Thp1PjkrcI9/jELdWzoFsDZoc6v5XgH2t2l60tUrO+oQwOSawzPc5egoi1YvLh75uvpg== +bitcore-lib@^10.3.0: + version "10.3.0" + resolved "https://registry.yarnpkg.com/bitcore-lib/-/bitcore-lib-10.3.0.tgz#d58dabe7b019ad3d565c3d0837db50774a89d545" + integrity sha512-q+O4M4adn2iJcBNcVch/KYu81LKEKrUV7VoC0N5qNAzkNIOmuj3kHf90Q2muYx3f+ZP3Mq5Eoqtx1yPcZFDbrg== dependencies: bech32 "=2.0.0" bn.js "=4.11.8" @@ -5797,24 +5797,24 @@ bitcore-lib@^10.2.1: inherits "=2.0.1" lodash "^4.17.20" -bitcore-mnemonic@^10.2.1: - version "10.2.1" - resolved "https://registry.yarnpkg.com/bitcore-mnemonic/-/bitcore-mnemonic-10.2.1.tgz#c5cc495fdb415221ee16c8844c935290ff0fb7c2" - integrity sha512-rkpj3bG091bbhY26Nh3tQKsKAGBUuCfvWQi9rHkkCUuPiI1blMw7dFyKAJMiC0Bcs/0P7VsCey49GHa/9Xc3MQ== +bitcore-mnemonic@^10.3.0: + version "10.3.0" + resolved "https://registry.yarnpkg.com/bitcore-mnemonic/-/bitcore-mnemonic-10.3.0.tgz#9a52cd0c6ac442b01975993eb142eae8c56e28fb" + integrity sha512-pBPcpAL1CLHUnL/BphkcifpN1eWlyIQwcPijEPEwh27E13Yuw8X8edh4Wf2PpPfvmEF5bp3c5I5QRa/2apGUYw== dependencies: - bitcore-lib "^10.2.1" + bitcore-lib "^10.3.0" unorm "^1.4.1" -bitcore-wallet-client@10.2.1: - version "10.2.1" - resolved "https://registry.yarnpkg.com/bitcore-wallet-client/-/bitcore-wallet-client-10.2.1.tgz#15d3147d206123cd7cc7b00e7d0eb95bad918c23" - integrity sha512-jUJSWAnNI89AITPmtU63tbzoQFRrgOuDdasfTSlllUjMg+Oxa8RSGc6yjxC5uOqZ8o7r1+YLgNy0gdmilv9PMw== +bitcore-wallet-client@10.3.0: + version "10.3.0" + resolved "https://registry.yarnpkg.com/bitcore-wallet-client/-/bitcore-wallet-client-10.3.0.tgz#da29ae41165626a6695d5ecc072813e8116cee83" + integrity sha512-VZZL2COMdkr32s+VnlqarhpfFQaOoyxF0FirazziL4qNKE+vy1bnZPhdFMxv7yUAngUl3hCIQSYHGVozg23OmQ== dependencies: ajv "6.12.0" async "0.9.2" bip38 "1.4.0" - bitcore-mnemonic "^10.2.1" - crypto-wallet-core "^10.2.1" + bitcore-mnemonic "^10.3.0" + crypto-wallet-core "^10.3.0" json-stable-stringify "1.0.1" lodash "4.17.20" preconditions "2.2.3" @@ -6976,12 +6976,12 @@ crypto-js@3.1.9-1: resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-3.1.9-1.tgz#fda19e761fc077e01ffbfdc6e9fdfc59e8806cd8" integrity sha512-W93aKztssqf29OvUlqfikzGyYbD1rpkXvGP9IQ1JchLY3bxaLXZSWYbwrtib2vk8DobrDzX7PIXcDWHp0B6Ymw== -crypto-wallet-core@^10.2.1: - version "10.2.1" - resolved "https://registry.yarnpkg.com/crypto-wallet-core/-/crypto-wallet-core-10.2.1.tgz#19eebf137ec6535b5d86343b41d70d89023573a1" - integrity sha512-CKFwDKEBVtYECru86dcySSe/QtCEJEErQOZvKN/a7bYve61qzPPLIFl9pwypW7PS4JUWACb30XB1gTwUobtiJQ== +crypto-wallet-core@^10.3.0: + version "10.3.0" + resolved "https://registry.yarnpkg.com/crypto-wallet-core/-/crypto-wallet-core-10.3.0.tgz#339fd570300b5b89aac1211cc9bed210005f8254" + integrity sha512-ElClXc+AA4yAu3q06vEMgSN7bNlwD6GLnDBHU/8C3NZE+U7dGW5RZY8wGxXLs8L28XSu13I4UjNQsIGjudrrGQ== dependencies: - bitcore-lib "^10.2.1" + bitcore-lib "^10.3.0" bitcore-lib-cash "^10.0.39" bitcore-lib-doge "^10.0.36" bitcore-lib-ltc "^10.0.36"