From 47239e66cdcaa42a18552a1cd8df03667a455f47 Mon Sep 17 00:00:00 2001 From: kyranjamie Date: Fri, 21 Jul 2023 16:14:29 +0200 Subject: [PATCH] refactor: remove unused address regeneration code, ref #2894 --- src/app/components/text/capitalize.tsx | 5 ++ .../components/ledger-inline-warnings.tsx | 7 +- .../ledger/components/ledger-title.tsx | 4 +- .../request-keys/use-request-ledger-keys.ts | 2 - .../connect-device/connect-ledger.layout.tsx | 4 +- .../use-next-fresh-taproot-address.query.ts | 75 ------------------- src/app/query/bitcoin/ordinals/utils.ts | 2 +- src/app/store/keys/key.slice.ts | 2 - tests/page-object-models/onboarding.page.ts | 6 ++ 9 files changed, 20 insertions(+), 87 deletions(-) create mode 100644 src/app/components/text/capitalize.tsx delete mode 100644 src/app/query/bitcoin/ordinals/use-next-fresh-taproot-address.query.ts diff --git a/src/app/components/text/capitalize.tsx b/src/app/components/text/capitalize.tsx new file mode 100644 index 00000000..65fcc034 --- /dev/null +++ b/src/app/components/text/capitalize.tsx @@ -0,0 +1,5 @@ +import styled from '@emotion/styled'; + +export const Capitalize = styled.span` + text-transform: capitalize; +`; diff --git a/src/app/features/ledger/components/ledger-inline-warnings.tsx b/src/app/features/ledger/components/ledger-inline-warnings.tsx index 535835c3..021a7472 100644 --- a/src/app/features/ledger/components/ledger-inline-warnings.tsx +++ b/src/app/features/ledger/components/ledger-inline-warnings.tsx @@ -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 ( - Latest version of {capitalize(chain)} app required + Latest version of {chain} app required Update on Ledger Live to continue @@ -38,7 +38,8 @@ export function CommonLedgerDeviceInlineWarnings({ if (isStacksLedgerAppClosed(latestDeviceResponse)) return ( - The {capitalize(chain)} app appears to be closed on Ledger. Open it to continue. + The {chain} app appears to be closed on Ledger. Open it to + continue. ); return null; diff --git a/src/app/features/ledger/components/ledger-title.tsx b/src/app/features/ledger/components/ledger-title.tsx index 7d3c4156..7bb1a496 100644 --- a/src/app/features/ledger/components/ledger-title.tsx +++ b/src/app/features/ledger/components/ledger-title.tsx @@ -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 ( - Plug in your Ledger, open the {capitalize(chain)} app and click connect + Plug in your Ledger, open the (chain) app and click connect ); } diff --git a/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts b/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts index 4efcc10a..ab1607fa 100644 --- a/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts +++ b/src/app/features/ledger/generic-flows/request-keys/use-request-ledger-keys.ts @@ -80,8 +80,6 @@ export function useRequestLedgerKeys({ 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') || diff --git a/src/app/features/ledger/generic-steps/connect-device/connect-ledger.layout.tsx b/src/app/features/ledger/generic-steps/connect-device/connect-ledger.layout.tsx index 8bac3cce..784058e9 100644 --- a/src/app/features/ledger/generic-steps/connect-device/connect-ledger.layout.tsx +++ b/src/app/features/ledger/generic-steps/connect-device/connect-ledger.layout.tsx @@ -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 {chain} app ) : null} diff --git a/src/app/query/bitcoin/ordinals/use-next-fresh-taproot-address.query.ts b/src/app/query/bitcoin/ordinals/use-next-fresh-taproot-address.query.ts deleted file mode 100644 index 3746d747..00000000 --- a/src/app/query/bitcoin/ordinals/use-next-fresh-taproot-address.query.ts +++ /dev/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, - } - ); -} diff --git a/src/app/query/bitcoin/ordinals/utils.ts b/src/app/query/bitcoin/ordinals/utils.ts index 219d54d6..bf1cad29 100644 --- a/src/app/query/bitcoin/ordinals/utils.ts +++ b/src/app/query/bitcoin/ordinals/utils.ts @@ -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); diff --git a/src/app/store/keys/key.slice.ts b/src/app/store/keys/key.slice.ts index fe9d6587..5c5668dd 100644 --- a/src/app/store/keys/key.slice.ts +++ b/src/app/store/keys/key.slice.ts @@ -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; targetId: string; } diff --git a/tests/page-object-models/onboarding.page.ts b/tests/page-object-models/onboarding.page.ts index 34e379bb..d8a0fe01 100644 --- a/tests/page-object-models/onboarding.page.ts +++ b/tests/page-object-models/onboarding.page.ts @@ -21,6 +21,12 @@ export const testSoftwareAccountDefaultWalletState = { }, }, }, + ledger: { + bitcoin: { + entities: {}, + ids: [], + }, + }, networks: { ids: [], entities: {}, currentNetworkId: 'mainnet' }, onboarding: { hideSteps: true,