Skip to content

Commit

Permalink
render bitcoin network
Browse files Browse the repository at this point in the history
  • Loading branch information
owencraston committed Nov 16, 2024
1 parent eb4fffe commit 00ccccb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
39 changes: 28 additions & 11 deletions app/components/UI/Navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import AddressCopy from '../AddressCopy';
import PickerAccount from '../../../component-library/components/Pickers/PickerAccount';
import { createAccountSelectorNavDetails } from '../../../components/Views/AccountSelector';
import { RequestPaymentViewSelectors } from '../../../../e2e/selectors/Receive/RequestPaymentView.selectors';
import { EthAccountType, BtcAccountType } from '@metamask/keyring-api';
import { toChecksumHexAddress } from '@metamask/controller-utils';

const trackEvent = (event, params = {}) => {
MetaMetrics.getInstance().trackEvent(event, params);
Expand Down Expand Up @@ -910,7 +912,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 @@ -926,7 +928,7 @@ export function getOfflineModalNavbar() {
*/
export function getWalletNavbarOptions(
accountActionsRef,
selectedAddress,
selectedInternalAccount,
accountName,
accountAvatarType,
networkName,
Expand Down Expand Up @@ -955,6 +957,15 @@ export function getWalletNavbarOptions(
},
});

console.log('Bitcoin/ selectedInternalAccount', selectedInternalAccount);
console.log('Bitcoin/ network name', networkName);

const formattedAddress =
selectedInternalAccount.type === EthAccountType.Eoa ||
selectedInternalAccount.type === EthAccountType.Erc4337
? toChecksumHexAddress(selectedInternalAccount.address)
: selectedInternalAccount.address;

const onScanSuccess = (data, content) => {
if (data.private_key) {
Alert.alert(
Expand Down Expand Up @@ -1027,13 +1038,15 @@ export function getWalletNavbarOptions(
<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}
Expand All @@ -1042,13 +1055,17 @@ export function getWalletNavbarOptions(
),
headerLeft: () => (
<View style={styles.leftElementContainer}>
<PickerNetwork
label={networkName}
imageSource={networkImageSource}
onPress={onPressTitle}
testID={WalletViewSelectorsIDs.NAVBAR_NETWORK_BUTTON}
hideNetworkName
/>
{selectedInternalAccount.type === BtcAccountType.P2wpkh ? (
<Text>Bitcoin</Text>
) : (
<PickerNetwork
label={networkName}
imageSource={networkImageSource}
onPress={onPressTitle}
testID={WalletViewSelectorsIDs.NAVBAR_NETWORK_BUTTON}
hideNetworkName
/>
)}
</View>
),
headerRight: () => (
Expand Down
12 changes: 5 additions & 7 deletions app/components/Views/Wallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import Text, {
import { useMetrics } from '../../../components/hooks/useMetrics';
import { RootState } from '../../../reducers';
import usePrevious from '../../hooks/usePrevious';
import { selectSelectedInternalAccountFormattedAddress } from '../../../selectors/accountsController';
import { selectSelectedInternalAccount } from '../../../selectors/accountsController';
import { selectAccountBalanceByChainId } from '../../../selectors/accountTrackerController';
import {
hideNftFetchingLoadingIndicator as hideNftFetchingLoadingIndicatorAction,
Expand Down Expand Up @@ -179,9 +179,7 @@ const Wallet = ({
/**
* A string that represents the selected address
*/
const selectedAddress = useSelector(
selectSelectedInternalAccountFormattedAddress,
);
const selectedInternalAccount = useSelector(selectSelectedInternalAccount);
/**
* An array that represents the user tokens
*/
Expand Down Expand Up @@ -406,7 +404,7 @@ const Wallet = ({
navigation.setOptions(
getWalletNavbarOptions(
walletRef,
selectedAddress || '',
selectedInternalAccount || '',
accountName,
accountAvatarType,
networkName,
Expand All @@ -422,7 +420,7 @@ const Wallet = ({
);
/* eslint-disable-next-line */
}, [
selectedAddress,
selectedInternalAccount,
accountName,
accountAvatarType,
navigation,
Expand Down Expand Up @@ -625,7 +623,7 @@ const Wallet = ({
return (
<ErrorBoundary navigation={navigation} view="Wallet">
<View style={baseStyles.flexGrow}>
{selectedAddress ? renderContent() : renderLoader()}
{selectedInternalAccount ? renderContent() : renderLoader()}

{renderOnboardingWizard()}
</View>
Expand Down
1 change: 0 additions & 1 deletion app/components/hooks/useAccounts/useAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
UseAccountsParams,
} from './useAccounts.types';
import { InternalAccount, EthAccountType } from '@metamask/keyring-api';
import { Hex } from '@metamask/utils';
import { BigNumber } from 'ethers';

/**
Expand Down
1 change: 0 additions & 1 deletion app/components/hooks/useAccounts/useAccounts.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Third party dependencies.
import { KeyringTypes } from '@metamask/keyring-controller';
import { Hex } from '@metamask/utils';

// External dependencies.
import { AvatarTokenProps } from '../../../component-library/components/Avatars/Avatar/variants/AvatarToken/AvatarToken.types';
Expand Down

0 comments on commit 00ccccb

Please sign in to comment.