Skip to content

Commit

Permalink
fix: add remote config to recover feature
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jan 16, 2024
1 parent 227f6ee commit 84a10dc
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 13 deletions.
3 changes: 2 additions & 1 deletion config/wallet-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,6 @@
"integrationEnabled": true,
"mainnetApiUrl": "https://api2.ordinalsbot.com",
"signetApiUrl": "https://signet.ordinalsbot.com"
}
},
"recoverUninscribedTaprootUtxosFeatureEnabled": false
}
4 changes: 4 additions & 0 deletions config/wallet-config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
"mainnetApiUrl": { "type": "string" },
"signetApiUrl": { "type": "string" }
}
},
"recoverUninscribedTaprootUtxosFeatureEnabled": {
"type": "boolean",
"description": "Determines whether or not the recover uninscribed taproot utxos feature is enabled"
}
},
"$defs": {
Expand Down
8 changes: 6 additions & 2 deletions src/app/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as reduxPersist from 'redux-persist';
import { getLogsFromBrowserStorage } from '@shared/logger-storage';
import { persistConfig } from '@shared/storage/redux-pesist';

import { queryClient } from './common/persistence';
import { store } from './store';
import { stxChainSlice } from './store/chains/stx-chain.slice';
import { settingsSlice } from './store/settings/settings.slice';
Expand Down Expand Up @@ -34,8 +35,11 @@ const debug = {
resetMessages() {
store.dispatch(settingsSlice.actions.resetMessages());
},
resetHasApprovedNewBrand() {
store.dispatch(settingsSlice.actions.resetHasApprovedNewBrand());
clearReactQueryCache() {
queryClient.clear();
},
clearChromeStorage() {
chrome.storage.local.clear();
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { formatMoney } from '@app/common/money/format-money';
import { Tooltip } from '@app/components/tooltip';
import { useCurrentTaprootAccountBalance } from '@app/query/bitcoin/balance/btc-taproot-balance.hooks';
import { useRecoverUninscribedTaprootUtxosFeatureEnabled } from '@app/query/common/remote-config/remote-config.query';
import { LeatherButton } from '@app/ui/components/button';

const taprootSpendNotSupportedYetMsg = `
Expand All @@ -13,6 +14,8 @@ interface TaprootBalanceDisplayerProps {
}
export function TaprootBalanceDisplayer({ onSelectRetrieveBalance }: TaprootBalanceDisplayerProps) {
const balance = useCurrentTaprootAccountBalance();
const isRecoverFeatureEnabled = useRecoverUninscribedTaprootUtxosFeatureEnabled();
if (!isRecoverFeatureEnabled) return null;
if (balance.amount.isLessThanOrEqualTo(0)) return null;
return (
<Tooltip label={taprootSpendNotSupportedYetMsg}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ export function RetrieveTaprootToNativeSegwit() {
key={utxo.txid}
title={`Uninscribed UTXO #${i}`}
value={
<ExternalLink
href={`https://ordinals-explorer.generative.xyz/output/${utxo.txid}:${utxo.vout}`}
>
<ExternalLink href={`https://ordinals.com/output/${utxo.txid}:${utxo.vout}`}>
{`${truncateMiddle(utxo.txid, 4)}:${utxo.vout}`}
</ExternalLink>
}
Expand Down
12 changes: 5 additions & 7 deletions src/app/query/bitcoin/address/utxos-by-address.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function useGetUtxosByAddressQuery<T extends unknown = UtxoResponseItem[]
});
}

const stopSearchAfterNumberAddressesWithoutOrdinals = 20;
const stopSearchAfterNumberAddressesWithoutUtxos = 20;

/**
* Returns all utxos for the user's current taproot account. The search for
Expand All @@ -48,12 +48,10 @@ export function useTaprootAccountUtxosQuery() {
return useQuery(
[QueryPrefixes.TaprootAddressUtxos, currentAccountIndex, network.id],
async () => {
let currentNumberOfAddressesWithoutOrdinals = 0;
let currentNumberOfAddressesWithoutUtxos = 0;
const addressIndexCounter = createCounter(0);
let foundUnspentTransactions: TaprootUtxo[] = [];
while (
currentNumberOfAddressesWithoutOrdinals < stopSearchAfterNumberAddressesWithoutOrdinals
) {
while (currentNumberOfAddressesWithoutUtxos < stopSearchAfterNumberAddressesWithoutUtxos) {
const address = getTaprootAddress({
index: addressIndexCounter.getValue(),
keychain: account?.keychain,
Expand All @@ -63,7 +61,7 @@ export function useTaprootAccountUtxosQuery() {
const unspentTransactions = await client.addressApi.getUtxosByAddress(address);

if (!hasInscriptions(unspentTransactions)) {
currentNumberOfAddressesWithoutOrdinals += 1;
currentNumberOfAddressesWithoutUtxos += 1;
addressIndexCounter.increment();
continue;
}
Expand All @@ -77,7 +75,7 @@ export function useTaprootAccountUtxosQuery() {
...foundUnspentTransactions,
];

currentNumberOfAddressesWithoutOrdinals = 0;
currentNumberOfAddressesWithoutUtxos = 0;
addressIndexCounter.increment();
}
return foundUnspentTransactions;
Expand Down
1 change: 1 addition & 0 deletions src/app/query/bitcoin/balance/btc-taproot-balance.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useGetInscriptionsInfiniteQuery } from '../ordinals/inscriptions.query'

export function useCurrentTaprootAccountUninscribedUtxos() {
const { data: utxos = [] } = useTaprootAccountUtxosQuery();

const query = useGetInscriptionsInfiniteQuery();

return useMemo(() => {
Expand Down
5 changes: 5 additions & 0 deletions src/app/query/common/remote-config/remote-config.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ export function useConfigBitcoinSendEnabled() {
});
}

export function useRecoverUninscribedTaprootUtxosFeatureEnabled() {
const config = useRemoteConfig();
return get(config, 'recoverUninscribedTaprootUtxosFeatureEnabled', false);
}

export function useConfigFeeEstimationsMaxEnabled() {
const config = useRemoteConfig();
if (isUndefined(config) || isUndefined(config?.feeEstimationsMinMax)) return;
Expand Down

0 comments on commit 84a10dc

Please sign in to comment.