fix: ordinal inscription address

This commit is contained in:
alter-eggo
2023-03-14 21:32:45 +04:00
committed by kyranjamie
parent 9dd8796e7e
commit a5e4e8ec83
6 changed files with 29 additions and 12 deletions

View File

@@ -1,9 +1,10 @@
import toast from 'react-hot-toast';
import { FiCopy } from 'react-icons/fi';
import { useNavigate } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { Box, Button, Flex, Stack, useClipboard } from '@stacks/ui';
import { truncateMiddle } from '@stacks/ui-utils';
import get from 'lodash.get';
import { RouteUrls } from '@shared/route-urls';
@@ -18,7 +19,10 @@ import { useCurrentAccountStxAddressState } from '@app/store/accounts/blockchain
export function ReceiveCollectible() {
const analytics = useAnalytics();
const navigate = useNavigate();
const { isLoading, isError, data: btcAddress } = useNextFreshTaprootAddressQuery();
const location = useLocation();
const accountIndex = get(location.state, 'accountIndex', undefined);
const { isLoading, isError, data: btcAddress } = useNextFreshTaprootAddressQuery(accountIndex);
const stxAddress = useCurrentAccountStxAddressState();
const { onCopy: onCopyStacks } = useClipboard(stxAddress);

View File

@@ -54,7 +54,7 @@ export const SwitchAccountListItem = memo(
const onClickBtcCopyIcon = (e: React.MouseEvent) => {
e.stopPropagation();
setIsShowingSwitchAccountsState(false);
navigate(RouteUrls.ReceiveBtc, { state: { btcAddress } });
navigate(RouteUrls.ReceiveBtc, { state: { btcAddress, accountIndex: account.index } });
};
return (

View File

@@ -7,7 +7,11 @@ import { RouteUrls } from '@shared/route-urls';
import { Link } from '@app/components/link';
import { WarningLabel } from '@app/components/warning-label';
export function ReceiveBtcModalWarning() {
interface ReceiveBtcModalWarningProps {
accountIndex: number;
}
export function ReceiveBtcModalWarning({ accountIndex }: ReceiveBtcModalWarningProps) {
const navigate = useNavigate();
return (
@@ -17,7 +21,7 @@ export function ReceiveBtcModalWarning() {
Do not deposit Ordinal inscriptions here
</Text>
<Link
onClick={() => navigate(RouteUrls.ReceiveCollectible)}
onClick={() => navigate(RouteUrls.ReceiveCollectible, { state: { accountIndex } })}
color="blue"
display="inline-block"
fontSize={1}

View File

@@ -12,10 +12,13 @@ import { ReceiveBtcModalWarning } from './components/receive-btc-warning';
import { ReceiveTokensLayout } from './components/receive-tokens.layout';
export function ReceiveBtcModal() {
const accountIndex = useCurrentAccountIndex();
const activeAccountBtcAddress = useBtcNativeSegwitAccountIndexAddressIndexZero(accountIndex);
const analytics = useAnalytics();
const { state } = useLocation();
const currentAccountIndex = useCurrentAccountIndex();
const accountIndex = get(state, 'accountIndex', currentAccountIndex);
const activeAccountBtcAddress = useBtcNativeSegwitAccountIndexAddressIndexZero(accountIndex);
const btcAddress = get(state, 'btcAddress', activeAccountBtcAddress);
const { onCopy } = useClipboard(btcAddress);
@@ -31,7 +34,7 @@ export function ReceiveBtcModal() {
address={btcAddress}
onCopyAddressToClipboard={copyToClipboard}
title="Bitcoin address"
warning={ReceiveBtcModalWarning()}
warning={<ReceiveBtcModalWarning accountIndex={accountIndex} />}
hasSubtitle={false}
/>
);

View File

@@ -6,13 +6,15 @@ import { useQuery } from '@tanstack/react-query';
import { createCounter } from '@app/common/utils/counter';
import { UtxoResponseItem } from '@app/query/bitcoin/bitcoin-client';
import { getTaprootAddress } from '@app/query/bitcoin/ordinals/utils';
import { useCurrentTaprootAccountKeychain } from '@app/store/accounts/blockchain/bitcoin/taproot-account.hooks';
import { useCurrentAccountIndex } from '@app/store/accounts/account';
import { useTaprootAccountKeychain } from '@app/store/accounts/blockchain/bitcoin/taproot-account.hooks';
import { useBitcoinClient } from '@app/store/common/api-clients.hooks';
import { useCurrentNetwork } from '@app/store/networks/networks.selectors';
export function useNextFreshTaprootAddressQuery() {
export function useNextFreshTaprootAddressQuery(accIndex?: number) {
const network = useCurrentNetwork();
const keychain = useCurrentTaprootAccountKeychain();
const currentAccountIndex = useCurrentAccountIndex();
const keychain = useTaprootAccountKeychain(accIndex ?? currentAccountIndex);
const client = useBitcoinClient();
const [highestKnownAccountActivity, setHighestKnownAccountActivity] = useState(0);

View File

@@ -31,9 +31,13 @@ function useTaprootCurrentNetworkAccountKeychain() {
export function useCurrentTaprootAccountKeychain() {
const currentAccountIndex = useCurrentAccountIndex();
return useTaprootAccountKeychain(currentAccountIndex);
}
export function useTaprootAccountKeychain(accountIndex: number) {
const accountKeychain = useTaprootCurrentNetworkAccountKeychain();
if (!accountKeychain) return; // TODO: Revisit this return early
const keychain = accountKeychain(currentAccountIndex);
const keychain = accountKeychain(accountIndex);
if (!keychain) throw new Error('No account keychain found');
return keychain;
}