Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Add taproot support #1267

Merged
merged 7 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
46 changes: 37 additions & 9 deletions src/navigation/wallet/screens/AddWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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';
Expand Down Expand Up @@ -288,7 +292,9 @@ const AddWallet = ({
BitpaySupportedCoins[currencyAbbreviation?.toLowerCase() as string]
?.properties?.singleAddress;
const nativeSegwitCurrency = IsSegwitCoin(_currencyAbbreviation);
const taprootCurrency = IsTaprootCoin(_currencyAbbreviation);
const [useNativeSegwit, setUseNativeSegwit] = useState(nativeSegwitCurrency);
const [segwitVersion, setSegwitVersion] = useState(0);
const [evmWallets, setEvmWallets] = useState<Wallet[] | undefined>();
const [accountsInfo, setAccountsInfo] = useState<AccountSelectorProps[]>([]);
const [associatedWallet, setAssociatedWallet] = useState<
Expand Down Expand Up @@ -337,6 +343,16 @@ const AddWallet = ({
});
}, [navigation, t]);

const toggleUseNativeSegwit = () => {
setUseNativeSegwit(!(useNativeSegwit && segwitVersion === 0));
setSegwitVersion(0);
};

const toggleUseTaproot = () => {
setUseNativeSegwit(!(useNativeSegwit && segwitVersion === 1));
setSegwitVersion(1);
};

const addAssociatedWallet = async () => {
try {
const evmCoinOption = SupportedCoinsOptions.find(
Expand Down Expand Up @@ -580,6 +596,7 @@ const AddWallet = ({
? Network.regtest
: network,
useNativeSegwit,
segwitVersion,
singleAddress,
walletName,
...(account !== undefined && {
Expand Down Expand Up @@ -1016,19 +1033,30 @@ const AddWallet = ({

{showOptions && nativeSegwitCurrency && (
<AdvancedOptions>
<RowContainer
onPress={() => {
setUseNativeSegwit(!useNativeSegwit);
}}>
<RowContainer onPress={() => toggleUseNativeSegwit()}>
<Column>
<OptionTitle>Segwit</OptionTitle>
</Column>
<CheckBoxContainer>
<Checkbox
checked={useNativeSegwit}
onPress={() => {
setUseNativeSegwit(!useNativeSegwit);
}}
checked={useNativeSegwit && segwitVersion === 0}
onPress={() => toggleUseNativeSegwit()}
/>
</CheckBoxContainer>
</RowContainer>
</AdvancedOptions>
)}

{showOptions && taprootCurrency && (
<AdvancedOptions>
<RowContainer onPress={() => toggleUseTaproot()}>
<Column>
<OptionTitle>Taproot</OptionTitle>
</Column>
<CheckBoxContainer>
<Checkbox
checked={useNativeSegwit && segwitVersion === 1}
onPress={() => toggleUseTaproot()}
/>
</CheckBoxContainer>
</RowContainer>
Expand Down
5 changes: 5 additions & 0 deletions src/navigation/wallet/screens/WalletDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
buildUIFormattedWallet,
findWalletById,
isSegwit,
isTaproot,
} from '../../../store/wallet/utils/wallet';
import {
setWalletScanning,
Expand Down Expand Up @@ -284,6 +285,10 @@ const getWalletType = (
if (isSegwit(addressType)) {
return {title: 'Segwit'};
}

if (isTaproot(addressType)) {
return {title: 'Taproot'};
}
return;
};

Expand Down
3 changes: 3 additions & 0 deletions src/store/wallet/effects/create/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface CreateOptions {
account?: number;
customAccount?: boolean;
useNativeSegwit?: boolean;
segwitVersion?: number;
singleAddress?: boolean;
walletName?: string;
password?: string;
Expand Down Expand Up @@ -389,6 +390,7 @@ const createWallet =
password,
singleAddress,
useNativeSegwit,
segwitVersion,
} = {
...DEFAULT_CREATION_OPTIONS,
...options,
Expand Down Expand Up @@ -417,6 +419,7 @@ const createWallet =
coin,
chain,
useNativeSegwit,
segwitVersion,
},
(err: any) => {
if (err) {
Expand Down
4 changes: 4 additions & 0 deletions src/store/wallet/utils/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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 IsUtxoChain = (chain: string): boolean => {
const _chain = cloneDeep(chain).toLowerCase();

Expand Down
8 changes: 8 additions & 0 deletions src/store/wallet/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,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,
Expand Down
40 changes: 20 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down