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

Test/bitcoin bdk #12454

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5cabad7
create bitcoin account
owencraston Nov 13, 2024
ecc6aa2
migrate to selectSelectedInternalAccountFormattedAddress
owencraston Nov 13, 2024
b28e0d7
shorten btc address
owencraston Nov 13, 2024
3925733
check if bitcoin address is valid
owencraston Nov 14, 2024
9bbc452
close after creating bitcoin account
owencraston Nov 15, 2024
f69de3a
render bitcoin network
owencraston Nov 16, 2024
d04eb73
show bitcoin network icon
owencraston Nov 20, 2024
1bc0756
disable network picker
owencraston Nov 20, 2024
fd34674
remove console.log
owencraston Nov 20, 2024
ebff791
bitcoin account selectors and utils
owencraston Nov 21, 2024
7058fb0
add tests for BTC selectors
owencraston Nov 21, 2024
64034ca
more code fencing
owencraston Nov 21, 2024
12bc7e6
ore cleanup
owencraston Nov 21, 2024
9b0f659
multichain utils test
owencraston Nov 21, 2024
d714b53
update snapshot tests
owencraston Nov 21, 2024
2413657
remove address validation
owencraston Nov 21, 2024
7200842
checksum eth addresses
owencraston Nov 21, 2024
55c9ced
add test cases for address utils with non evm
owencraston Nov 21, 2024
775f11d
update account permission snapshot
owencraston Nov 21, 2024
3023669
fix fence
owencraston Nov 21, 2024
4058920
update more snapshots
owencraston Nov 21, 2024
eb78af9
revert xcode project change
owencraston Nov 21, 2024
2ea8f80
handle undefined selected address
owencraston Nov 21, 2024
4f6eb19
getFormattedAddressFromInternalAccount util function
owencraston Nov 21, 2024
27a1623
add comment about hex balances
owencraston Nov 21, 2024
5f98a22
more comments about balances
owencraston Nov 21, 2024
2934fb1
remove logs in snap keyring
owencraston Nov 21, 2024
4bebcb6
move multichain constants into MultiChain folder
owencraston Nov 21, 2024
1211eb7
improve Bitcoin address validation
owencraston Nov 22, 2024
f1ed856
toFormattedAddress util function
owencraston Nov 22, 2024
e2abb8c
improve accountsController selector test
owencraston Nov 22, 2024
edc074b
fix lint
owencraston Nov 22, 2024
41fb13a
code fence bitcoin snap
owencraston Nov 22, 2024
c2ed0f3
keep fixcing tests
owencraston Nov 22, 2024
5cd1490
fix ConnectQRHardware test
owencraston Nov 22, 2024
f5db8ee
create bitcoin feature flag and set it to false
owencraston Nov 26, 2024
bdfc68e
do not persist multichain settings so that it is testable
owencraston Nov 26, 2024
c55e461
pin new module version
owencraston Nov 26, 2024
5cc0069
add multichainSettings to test state
owencraston Nov 26, 2024
d624559
fix code fencing
owencraston Nov 26, 2024
6a97cb9
test bdk snap
owencraston Nov 26, 2024
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
4 changes: 4 additions & 0 deletions app/actions/multichain/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface MultichainSettingsState {
bitcoinSupportEnabled: boolean;
bitcoinTestnetSupportEnabled: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ const PickerNetwork = ({
label,
imageSource,
hideNetworkName,
disabled = false,
...props
}: PickerNetworkProps) => {
const { styles } = useStyles(stylesheet, { style });

return (
<TouchableOpacity style={styles.base} onPress={onPress} {...props}>
<TouchableOpacity
style={styles.base}
onPress={onPress}
disabled={disabled}
{...props}
>
<View style={hideNetworkName ? styles.networkIconContainer : null}>
<Avatar
variant={AvatarVariant.Network}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export interface PickerNetworkProps extends TouchableOpacityProps {
* Network label to display.
*/
label: string;
/**
* Optional Boolean to determine if the picker is pressable. Defaults to `false`.
*/
disabled?: boolean;
/**
* Callback to trigger when picker is pressed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

exports[`PickerNetwork renders correctly 1`] = `
<TouchableOpacity
disabled={false}
onPress={[Function]}
style={
{
Expand Down
4 changes: 2 additions & 2 deletions app/components/Nav/Main/RootRPCMethodsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import TemplateConfirmationModal from '../../Approvals/TemplateConfirmationModal
import { selectTokenList } from '../../../selectors/tokenListController';
import { selectTokens } from '../../../selectors/tokensController';
import { getDeviceId } from '../../../core/Ledger/Ledger';
import { selectSelectedInternalAccountChecksummedAddress } from '../../../selectors/accountsController';
import { selectSelectedInternalAccountFormattedAddress } from '../../../selectors/accountsController';
import { createLedgerTransactionModalNavDetails } from '../../UI/LedgerModals/LedgerTransactionModal';
import ExtendedKeyringTypes from '../../../constants/keyringTypes';
import Confirm from '../../../components/Views/confirmations/Confirm';
Expand Down Expand Up @@ -559,7 +559,7 @@ RootRPCMethodsUI.propTypes = {
};

const mapStateToProps = (state) => ({
selectedAddress: selectSelectedInternalAccountChecksummedAddress(state),
selectedAddress: selectSelectedInternalAccountFormattedAddress(state),
chainId: selectChainId(state),
tokens: selectTokens(state),
providerType: selectProviderType(state),
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/AccountApproval/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Routes from '../../../constants/navigation/Routes';
import Engine from '../../../core/Engine';
import SDKConnect from '../../../core/SDKConnect/SDKConnect';
import { selectAccountsLength } from '../../../selectors/accountTrackerController';
import { selectSelectedInternalAccountChecksummedAddress } from '../../../selectors/accountsController';
import { selectSelectedInternalAccountFormattedAddress } from '../../../selectors/accountsController';
import {
selectChainId,
selectProviderType,
Expand Down Expand Up @@ -411,7 +411,7 @@ class AccountApproval extends PureComponent {
const mapStateToProps = (state) => ({
accountsLength: selectAccountsLength(state),
tokensLength: selectTokensLength(state),
selectedAddress: selectSelectedInternalAccountChecksummedAddress(state),
selectedAddress: selectSelectedInternalAccountFormattedAddress(state),
networkType: selectProviderType(state),
chainId: selectChainId(state),
});
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/AccountOverview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { selectChainId } from '../../../selectors/networkController';
import { selectCurrentCurrency } from '../../../selectors/currencyRateController';
import {
selectInternalAccounts,
selectSelectedInternalAccountChecksummedAddress,
selectSelectedInternalAccountFormattedAddress,
} from '../../../selectors/accountsController';
import { createAccountSelectorNavDetails } from '../../Views/AccountSelector';
import Text, {
Expand Down Expand Up @@ -450,7 +450,7 @@ class AccountOverview extends PureComponent {
}

const mapStateToProps = (state) => ({
selectedAddress: selectSelectedInternalAccountChecksummedAddress(state),
selectedAddress: selectSelectedInternalAccountFormattedAddress(state),
internalAccounts: selectInternalAccounts(state),
currentCurrency: selectCurrentCurrency(state),
chainId: selectChainId(state),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { FlatList } from 'react-native-gesture-handler';
import { useSelector } from 'react-redux';
import { useNavigation } from '@react-navigation/native';
import { KeyringTypes } from '@metamask/keyring-controller';
import type { Hex } from '@metamask/utils';

// External dependencies.
import { selectInternalAccounts } from '../../../selectors/accountsController';
Expand Down Expand Up @@ -120,7 +119,7 @@ const AccountSelectorList = ({
isSelected,
index,
}: {
address: Hex;
address: string;
imported: boolean;
isSelected: boolean;
index: number;
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/AddCustomCollectible/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { MetaMetricsEvents } from '../../../core/Analytics';
import { useTheme } from '../../../util/theme';
import { NFTImportScreenSelectorsIDs } from '../../../../e2e/selectors/wallet/ImportNFTView.selectors';
import { selectChainId } from '../../../selectors/networkController';
import { selectSelectedInternalAccountChecksummedAddress } from '../../../selectors/accountsController';
import { selectSelectedInternalAccountFormattedAddress } from '../../../selectors/accountsController';
import { getDecimalChainId } from '../../../util/networks';
import { useMetrics } from '../../../components/hooks/useMetrics';

Expand Down Expand Up @@ -84,7 +84,7 @@ const AddCustomCollectible = ({
const styles = createStyles(colors);

const selectedAddress = useSelector(
selectSelectedInternalAccountChecksummedAddress,
selectSelectedInternalAccountFormattedAddress,
);
const chainId = useSelector(selectChainId);

Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/AssetOverview/AssetOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { selectContractExchangeRates } from '../../../selectors/tokenRatesController';
import { selectAccountsByChainId } from '../../../selectors/accountTrackerController';
import { selectContractBalances } from '../../../selectors/tokenBalancesController';
import { selectSelectedInternalAccountChecksummedAddress } from '../../../selectors/accountsController';
import { selectSelectedInternalAccountFormattedAddress } from '../../../selectors/accountsController';
import Logger from '../../../util/Logger';
import { safeToChecksumAddress } from '../../../util/address';
import {
Expand Down Expand Up @@ -75,7 +75,7 @@ const AssetOverview: React.FC<AssetOverviewProps> = ({
);
const goToBridge = useGoToBridge('TokenDetails');
const selectedAddress = useSelector(
selectSelectedInternalAccountChecksummedAddress,
selectSelectedInternalAccountFormattedAddress,
);
const { trackEvent, createEventBuilder } = useMetrics();
const tokenExchangeRates = useSelector(selectContractExchangeRates);
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/CollectibleContractElement/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { removeFavoriteCollectible } from '../../../actions/collectibles';
import { collectibleContractsSelector } from '../../../reducers/collectibles';
import { useTheme } from '../../../util/theme';
import { selectChainId } from '../../../selectors/networkController';
import { selectSelectedInternalAccountChecksummedAddress } from '../../../selectors/accountsController';
import { selectSelectedInternalAccountFormattedAddress } from '../../../selectors/accountsController';
import Icon, {
IconName,
IconColor,
Expand Down Expand Up @@ -320,7 +320,7 @@ CollectibleContractElement.propTypes = {
const mapStateToProps = (state) => ({
collectibleContracts: collectibleContractsSelector(state),
chainId: selectChainId(state),
selectedAddress: selectSelectedInternalAccountChecksummedAddress(state),
selectedAddress: selectSelectedInternalAccountFormattedAddress(state),
});

const mapDispatchToProps = (dispatch) => ({
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/CollectibleContracts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
selectIsIpfsGatewayEnabled,
selectUseNftDetection,
} from '../../../selectors/preferencesController';
import { selectSelectedInternalAccountChecksummedAddress } from '../../../selectors/accountsController';
import { selectSelectedInternalAccountFormattedAddress } from '../../../selectors/accountsController';
import { WalletViewSelectorsIDs } from '../../../../e2e/selectors/wallet/WalletView.selectors';
import { useMetrics } from '../../../components/hooks/useMetrics';
import { RefreshTestId, SpinnerTestId } from './constants';
Expand Down Expand Up @@ -441,7 +441,7 @@ CollectibleContracts.propTypes = {
const mapStateToProps = (state) => ({
networkType: selectProviderType(state),
chainId: selectChainId(state),
selectedAddress: selectSelectedInternalAccountChecksummedAddress(state),
selectedAddress: selectSelectedInternalAccountFormattedAddress(state),
useNftDetection: selectUseNftDetection(state),
collectibleContracts: collectibleContractsSelector(state),
collectibles: collectiblesSelector(state),
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/CollectibleOverview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
selectDisplayNftMedia,
selectIsIpfsGatewayEnabled,
} from '../../../selectors/preferencesController';
import { selectSelectedInternalAccountChecksummedAddress } from '../../../selectors/accountsController';
import { selectSelectedInternalAccountFormattedAddress } from '../../../selectors/accountsController';

const ANIMATION_VELOCITY = 250;
const HAS_NOTCH = Device.hasNotch();
Expand Down Expand Up @@ -546,7 +546,7 @@ CollectibleOverview.propTypes = {

const mapStateToProps = (state, props) => ({
chainId: selectChainId(state),
selectedAddress: selectSelectedInternalAccountChecksummedAddress(state),
selectedAddress: selectSelectedInternalAccountFormattedAddress(state),
isInFavorites: isCollectibleInFavoritesSelector(state, props.collectible),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ exports[`ManageNetworks should render correctly 1`] = `
to learn more about how Infura handles data.
</Text>
<TouchableOpacity
disabled={false}
onPress={[Function]}
style={
{
Expand Down
65 changes: 49 additions & 16 deletions app/components/UI/Navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ import PickerAccount from '../../../component-library/components/Pickers/PickerA
import { createAccountSelectorNavDetails } from '../../../components/Views/AccountSelector';
import { RequestPaymentViewSelectors } from '../../../../e2e/selectors/Receive/RequestPaymentView.selectors';
import { MetricsEventBuilder } from '../../../core/Analytics/MetricsEventBuilder';
import { toChecksumHexAddress } from '@metamask/controller-utils';
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
import { isBtcAccount } from '../../../core/MultiChain/utils';
///: END:ONLY_INCLUDE_IF

const trackEvent = (event) => {
const trackEvent = (event, params = {}) => {
MetaMetrics.getInstance().trackEvent(event);
};

Expand Down Expand Up @@ -918,7 +922,7 @@ export function getOfflineModalNavbar() {
* Function that returns the navigation options for the wallet screen.
*
* @param {Object} accountActionsRef - The ref object for the account actions
* @param {string} selectedAddress - The currently selected Ethereum address
* @param {Object} selectedInternalAccount - The currently selected internal account
* @param {string} accountName - The name of the currently selected account
* @param {string} accountAvatarType - The type of avatar for the currently selected account
* @param {string} networkName - The name of the current network
Expand All @@ -934,7 +938,7 @@ export function getOfflineModalNavbar() {
*/
export function getWalletNavbarOptions(
accountActionsRef,
selectedAddress,
selectedInternalAccount,
accountName,
accountAvatarType,
networkName,
Expand Down Expand Up @@ -963,6 +967,15 @@ export function getWalletNavbarOptions(
},
});

let formattedAddress = toChecksumHexAddress(selectedInternalAccount.address);

///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
if (isBtcAccount(selectedInternalAccount)) {
// BTC addresses are not checksummed
formattedAddress = selectedInternalAccount.address;
}
///: END:ONLY_INCLUDE_IF

const onScanSuccess = (data, content) => {
if (data.private_key) {
Alert.alert(
Expand Down Expand Up @@ -1046,35 +1059,55 @@ export function getWalletNavbarOptions(
}
}

const renderNetworkPicker = () => {
let networkPicker = (
<PickerNetwork
label={networkName}
imageSource={networkImageSource}
onPress={onPressTitle}
testID={WalletViewSelectorsIDs.NAVBAR_NETWORK_BUTTON}
hideNetworkName
/>
);

///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
if (isBtcAccount(selectedInternalAccount)) {
networkPicker = (
<PickerNetwork
label={'Bitcoin'}
imageSource={require('../../../images/bitcoin-logo.png')}
testID={WalletViewSelectorsIDs.NAVBAR_NETWORK_BUTTON}
hideNetworkName
disabled
/>
);
}
///: END:ONLY_INCLUDE_IF

return <View style={styles.leftElementContainer}>{networkPicker}</View>;
};

return {
headerTitle: () => (
<View style={innerStyles.headerTitle}>
<PickerAccount
ref={accountActionsRef}
accountAddress={selectedAddress}
accountAddress={formattedAddress}
accountName={accountName}
accountAvatarType={accountAvatarType}
onPress={() => {
navigation.navigate(...createAccountSelectorNavDetails({}));
}}
accountTypeLabel={getLabelTextByAddress(selectedAddress) || undefined}
accountTypeLabel={
getLabelTextByAddress(formattedAddress) || undefined
}
showAddress
cellAccountContainerStyle={styles.account}
testID={WalletViewSelectorsIDs.ACCOUNT_ICON}
/>
</View>
),
headerLeft: () => (
<View style={styles.leftElementContainer}>
<PickerNetwork
label={networkName}
imageSource={networkImageSource}
onPress={onPressTitle}
testID={WalletViewSelectorsIDs.NAVBAR_NETWORK_BUTTON}
hideNetworkName
/>
</View>
),
headerLeft: () => renderNetworkPicker(),
headerRight: () => (
<View style={styles.rightElementContainer}>
<View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { selectTokensByAddress } from '../../../../selectors/tokensController';
import { selectContractExchangeRates } from '../../../../selectors/tokenRatesController';
import { selectAccounts } from '../../../../selectors/accountTrackerController';
import { speedUpTransaction } from '../../../../util/transaction-controller';
import { selectSelectedInternalAccountChecksummedAddress } from '../../../../selectors/accountsController';
import { selectSelectedInternalAccountFormattedAddress } from '../../../../selectors/accountsController';

const WINDOW_WIDTH = Dimensions.get('window').width;
const ACTION_CANCEL = 'cancel';
Expand Down Expand Up @@ -447,7 +447,7 @@ const mapStateToProps = (state) => {

return {
accounts: selectAccounts(state),
selectedAddress: selectSelectedInternalAccountChecksummedAddress(state),
selectedAddress: selectSelectedInternalAccountFormattedAddress(state),
transactions: TransactionController.transactions,
ticker: selectTicker(state),
chainId,
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/PaymentRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {
import { selectTokenListArray } from '../../../selectors/tokenListController';
import { selectTokens } from '../../../selectors/tokensController';
import { selectContractExchangeRates } from '../../../selectors/tokenRatesController';
import { selectSelectedInternalAccountChecksummedAddress } from '../../../selectors/accountsController';
import { selectSelectedInternalAccountFormattedAddress } from '../../../selectors/accountsController';

import { RequestPaymentViewSelectors } from '../../../../e2e/selectors/Receive/RequestPaymentView.selectors';

Expand Down Expand Up @@ -896,7 +896,7 @@ const mapStateToProps = (state) => ({
contractExchangeRates: selectContractExchangeRates(state),
searchEngine: state.settings.searchEngine,
tokens: selectTokens(state),
selectedAddress: selectSelectedInternalAccountChecksummedAddress(state),
selectedAddress: selectSelectedInternalAccountFormattedAddress(state),
primaryCurrency: state.settings.primaryCurrency,
ticker: selectTicker(state),
chainId: selectChainId(state),
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/Ramp/components/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useTheme } from '../../../../util/theme';
import { Colors } from '../../../../util/theme/models';
import { colors as importedColors } from '../../../../styles/common';
import {
selectSelectedInternalAccountChecksummedAddress,
selectSelectedInternalAccountFormattedAddress,
selectInternalAccounts,
} from '../../../../selectors/accountsController';
import { toLowerCaseEquals } from '../../../../util/general';
Expand Down Expand Up @@ -52,7 +52,7 @@ const Account = ({
const { colors } = useTheme();
const styles = createStyles(colors);
const selectedAddress = useSelector(
selectSelectedInternalAccountChecksummedAddress,
selectSelectedInternalAccountFormattedAddress,
);

const internalAccounts = useSelector(selectInternalAccounts);
Expand Down
Loading
Loading