mirror of
https://github.com/zhigang1992/wallet.git
synced 2026-01-12 22:53:27 +08:00
refactor: remove unused address regeneration code, ref #2894
This commit is contained in:
5
src/app/components/text/capitalize.tsx
Normal file
5
src/app/components/text/capitalize.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
import styled from '@emotion/styled';
|
||||
|
||||
export const Capitalize = styled.span`
|
||||
text-transform: capitalize;
|
||||
`;
|
||||
@@ -2,7 +2,7 @@ import { Text } from '@stacks/ui';
|
||||
|
||||
import { SupportedBlockchains } from '@shared/constants';
|
||||
|
||||
import { capitalize } from '@app/common/utils';
|
||||
import { Capitalize } from '@app/components/text/capitalize';
|
||||
import { WarningLabel } from '@app/components/warning-label';
|
||||
|
||||
import { isStacksLedgerAppClosed } from '../utils/stacks-ledger-utils';
|
||||
@@ -22,7 +22,7 @@ export function CommonLedgerDeviceInlineWarnings({
|
||||
if (outdatedLedgerAppWarning) {
|
||||
return (
|
||||
<WarningLabel fontSize="14px" textAlign="left">
|
||||
Latest version of <em>{capitalize(chain)} app</em> required
|
||||
Latest version of <Capitalize>{chain} app</Capitalize> required
|
||||
<Text as="a" textDecoration="underline" href="ledgerlive://manager">
|
||||
Update on Ledger Live to continue
|
||||
</Text>
|
||||
@@ -38,7 +38,8 @@ export function CommonLedgerDeviceInlineWarnings({
|
||||
if (isStacksLedgerAppClosed(latestDeviceResponse))
|
||||
return (
|
||||
<WarningLabel fontSize="14px" textAlign="left">
|
||||
The {capitalize(chain)} app appears to be closed on Ledger. Open it to continue.
|
||||
The <Capitalize>{chain}</Capitalize> app appears to be closed on Ledger. Open it to
|
||||
continue.
|
||||
</WarningLabel>
|
||||
);
|
||||
return null;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { BoxProps } from '@stacks/ui';
|
||||
|
||||
import { SupportedBlockchains } from '@shared/constants';
|
||||
|
||||
import { capitalize } from '@app/common/utils';
|
||||
import { Capitalize } from '@app/components/text/capitalize';
|
||||
import { Title } from '@app/components/typography';
|
||||
|
||||
export function LedgerTitle(props: BoxProps) {
|
||||
@@ -23,7 +23,7 @@ export function LedgerConnectInstructionTitle({
|
||||
}: LedgerConnectInstructionTitleProps) {
|
||||
return (
|
||||
<LedgerTitle {...props}>
|
||||
Plug in your Ledger, open the {capitalize(chain)} app and click connect
|
||||
Plug in your Ledger, open the <Capitalize>(chain)</Capitalize> app and click connect
|
||||
</LedgerTitle>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -80,8 +80,6 @@ export function useRequestLedgerKeys<App extends AppClient | StacksApp>({
|
||||
tap(() => onSuccess?.()),
|
||||
catchError(e => {
|
||||
setAwaitingDeviceConnection(false);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log({ name: e.name, msg: e.message });
|
||||
if (
|
||||
e.name === 'LockedDeviceError' ||
|
||||
e.message.includes('LockedDeviceError') ||
|
||||
|
||||
@@ -4,10 +4,10 @@ import { Box } from '@stacks/ui';
|
||||
|
||||
import { SupportedBlockchains } from '@shared/constants';
|
||||
|
||||
import { capitalize } from '@app/common/utils';
|
||||
import { ExternalLink } from '@app/components/external-link';
|
||||
import { Divider } from '@app/components/layout/divider';
|
||||
import { PrimaryButton } from '@app/components/primary-button';
|
||||
import { Capitalize } from '@app/components/text/capitalize';
|
||||
import { Caption } from '@app/components/typography';
|
||||
|
||||
import { LedgerConnectInstructionTitle } from '../../components/ledger-title';
|
||||
@@ -56,7 +56,7 @@ export function ConnectLedgerLayout(props: ConnectLedgerLayoutProps) {
|
||||
href="https://www.hiro.so/wallet-faq/how-can-i-use-my-ledger-device-with-hiro-wallet"
|
||||
fontSize={1}
|
||||
>
|
||||
See how to download the {capitalize(chain)} app
|
||||
See how to download the <Capitalize>{chain}</Capitalize> app
|
||||
</ExternalLink>
|
||||
</Box>
|
||||
) : null}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
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 { useCurrentAccountIndex } from '@app/store/accounts/account';
|
||||
import { useTaprootAccount } 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';
|
||||
|
||||
// ts-unused-exports:disable-next-line
|
||||
export function useNextFreshTaprootAddressQuery(accIndex?: number) {
|
||||
const network = useCurrentNetwork();
|
||||
const currentAccountIndex = useCurrentAccountIndex();
|
||||
const account = useTaprootAccount(accIndex ?? currentAccountIndex);
|
||||
const client = useBitcoinClient();
|
||||
|
||||
const [highestKnownAccountActivity, setHighestKnownAccountActivity] = useState(0);
|
||||
|
||||
return useQuery(
|
||||
['next-taproot-address', currentAccountIndex, network.id] as const,
|
||||
async () => {
|
||||
if (!account) throw new Error('Expected keychain to be provided');
|
||||
|
||||
async function taprootAddressIndexActivity(index: number) {
|
||||
const address = getTaprootAddress({
|
||||
index,
|
||||
keychain: account?.keychain,
|
||||
network: network.chain.bitcoin.network,
|
||||
});
|
||||
const utxos = await client.addressApi.getUtxosByAddress(address);
|
||||
return { address, utxos };
|
||||
}
|
||||
|
||||
const taprootUtxosByIndex: { index: number; address: string; utxos: UtxoResponseItem[] }[] =
|
||||
[];
|
||||
const counter = createCounter(highestKnownAccountActivity);
|
||||
|
||||
function hasFoundEmptyAddress() {
|
||||
return taprootUtxosByIndex.some(({ utxos }) => utxos.length === 0);
|
||||
}
|
||||
|
||||
while (!hasFoundEmptyAddress() || taprootUtxosByIndex.length === 0) {
|
||||
const { utxos, address } = await taprootAddressIndexActivity(counter.getValue());
|
||||
taprootUtxosByIndex.push({
|
||||
index: counter.getValue(),
|
||||
utxos,
|
||||
address,
|
||||
});
|
||||
counter.increment();
|
||||
}
|
||||
|
||||
const emptyAddresses = taprootUtxosByIndex.filter(({ utxos }) => utxos.length === 0);
|
||||
|
||||
if (emptyAddresses.length !== 1)
|
||||
throw new Error('Should not have found multiple empty addresses');
|
||||
|
||||
const [emptyAddress] = emptyAddresses;
|
||||
|
||||
// Check shouldn't be necessary, but just in case
|
||||
if (emptyAddress.utxos.length !== 0) throw new Error('Address found not empty');
|
||||
|
||||
setHighestKnownAccountActivity(Math.max(0, emptyAddress.index - 1));
|
||||
return emptyAddress.address;
|
||||
},
|
||||
{
|
||||
// This query needs to be run each time it is used as there is no way to
|
||||
// know whether the previously found address has received an ordinal since
|
||||
// it was last cached.
|
||||
cacheTime: 0,
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -23,7 +23,7 @@ export function getTaprootAddress({ index, keychain, network }: GetTaprootAddres
|
||||
const addressIndex = deriveAddressIndexKeychainFromAccount(keychain)(index);
|
||||
|
||||
if (!addressIndex.publicKey) {
|
||||
throw new Error('Expected privateKey to be defined');
|
||||
throw new Error('Expected publicKey to be defined');
|
||||
}
|
||||
|
||||
const payment = getTaprootPayment(addressIndex.publicKey!, network);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { PayloadAction, createEntityAdapter, createSlice } from '@reduxjs/toolkit';
|
||||
|
||||
import { BitcoinLedgerAccountDetails } from '@app/features/ledger/utils/bitcoin-ledger-utils';
|
||||
import { StxAndIdentityPublicKeys } from '@app/features/ledger/utils/stacks-ledger-utils';
|
||||
|
||||
import { migrateVaultReducerStoreToNewStateStructure } from '../utils/vault-reducer-migration';
|
||||
@@ -18,7 +17,6 @@ interface KeyConfigLedger {
|
||||
type: 'ledger';
|
||||
id: string;
|
||||
publicKeys: StxAndIdentityPublicKeys[];
|
||||
bitcoin?: Record<string, BitcoinLedgerAccountDetails>;
|
||||
targetId: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,12 @@ export const testSoftwareAccountDefaultWalletState = {
|
||||
},
|
||||
},
|
||||
},
|
||||
ledger: {
|
||||
bitcoin: {
|
||||
entities: {},
|
||||
ids: [],
|
||||
},
|
||||
},
|
||||
networks: { ids: [], entities: {}, currentNetworkId: 'mainnet' },
|
||||
onboarding: {
|
||||
hideSteps: true,
|
||||
|
||||
Reference in New Issue
Block a user