Skip to content

Commit

Permalink
fix(ledger): no signer breaking homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Apr 18, 2024
1 parent 2655c0f commit 7624c0a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
16 changes: 16 additions & 0 deletions src/app/components/account/bitcoin-account-loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useConfigBitcoinEnabled } from '@app/query/common/remote-config/remote-
import { useCurrentAccountIndex } from '@app/store/accounts/account';
import { Signer } from '@app/store/accounts/blockchain/bitcoin/bitcoin-signer';
import { useNativeSegwitSigner } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks';
import { useTaprootSigner } from '@app/store/accounts/blockchain/bitcoin/taproot-account.hooks';
import { useCurrentNetwork } from '@app/store/networks/networks.selectors';

interface BitcoinAccountLoaderBaseProps {
children(account: Signer<P2Ret>): React.ReactNode;
Expand All @@ -29,3 +31,17 @@ export function BitcoinNativeSegwitAccountLoader({ children, ...props }: BtcAcco
if (!signer || !isBitcoinEnabled) return null;
return children(signer(0));
}

export function BitcoinTaprootAccountLoader({ children, ...props }: BtcAccountLoaderProps) {
const isBitcoinEnabled = useConfigBitcoinEnabled();
const network = useCurrentNetwork();

const currentAccountIndex = useCurrentAccountIndex();

const properIndex = 'current' in props ? currentAccountIndex : props.index;

const signer = useTaprootSigner(properIndex, network.chain.bitcoin.bitcoinNetwork);

if (!signer || !isBitcoinEnabled) return null;
return children(signer(0));
}
27 changes: 16 additions & 11 deletions src/app/features/asset-list/asset-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import { Stack } from 'leather-styles/jsx';

import { useBtcAssetBalance } from '@app/common/hooks/balance/btc/use-btc-balance';
import { useWalletType } from '@app/common/use-wallet-type';
import {
BitcoinNativeSegwitAccountLoader,
BitcoinTaprootAccountLoader,
} from '@app/components/account/bitcoin-account-loader';
import { BitcoinContractEntryPoint } from '@app/components/bitcoin-contract-entry-point/bitcoin-contract-entry-point';
import { CryptoCurrencyAssetItemLayout } from '@app/components/crypto-assets/crypto-currency-asset/crypto-currency-asset-item.layout';
import { CurrentStacksAccountLoader } from '@app/components/loaders/stacks-account-loader';
import { useHasBitcoinLedgerKeychain } from '@app/store/accounts/blockchain/bitcoin/bitcoin.ledger';
import { useCurrentAccountNativeSegwitAddressIndexZero } from '@app/store/accounts/blockchain/bitcoin/native-segwit-account.hooks';
import { useCurrentAccountTaprootIndexZeroSigner } from '@app/store/accounts/blockchain/bitcoin/taproot-account.hooks';
import { useCurrentNetwork } from '@app/store/networks/networks.selectors';
import { BtcAvatarIcon } from '@app/ui/components/avatar/btc-avatar-icon';

Expand All @@ -25,7 +28,6 @@ import { StacksFungibleTokenAssetList } from './components/stacks-fungible-token
export function AssetsList() {
const hasBitcoinLedgerKeys = useHasBitcoinLedgerKeychain();
const bitcoinAddressNativeSegwit = useCurrentAccountNativeSegwitAddressIndexZero();
const { address: bitcoinAddressTaproot } = useCurrentAccountTaprootIndexZeroSigner();
const network = useCurrentNetwork();

const { btcAvailableAssetBalance, btcAvailableUsdBalance, isInitialLoading } = useBtcAssetBalance(
Expand Down Expand Up @@ -76,15 +78,18 @@ export function AssetsList() {
)}
</CurrentStacksAccountLoader>

{whenWallet({
software: (
<BitcoinFungibleTokenAssetList
btcAddressNativeSegwit={bitcoinAddressNativeSegwit}
btcAddressTaproot={bitcoinAddressTaproot}
/>
),
ledger: null,
})}
<BitcoinNativeSegwitAccountLoader current>
{nativeSegwitAccount => (
<BitcoinTaprootAccountLoader current>
{taprootAccount => (
<BitcoinFungibleTokenAssetList
btcAddressNativeSegwit={nativeSegwitAccount.address}
btcAddressTaproot={taprootAccount.address}
/>
)}
</BitcoinTaprootAccountLoader>
)}
</BitcoinNativeSegwitAccountLoader>

<PendingBrc20TransferList />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function useTaprootNetworkSigners() {
);
}

function useTaprootSigner(accountIndex: number, network: BitcoinNetworkModes) {
export function useTaprootSigner(accountIndex: number, network: BitcoinNetworkModes) {
const account = useTaprootAccount(accountIndex);
const extendedPublicKeyVersions = useBitcoinExtendedPublicKeyVersions();

Expand Down

0 comments on commit 7624c0a

Please sign in to comment.