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

fix(ledger): no signer breaking homepage #5254

Merged
merged 1 commit into from
Apr 18, 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
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
Loading