Skip to content

Commit 2e1fad5

Browse files
authored
fix: [LW-11938] remove inputs resolver that relies on chain history provider (#1574)
1 parent 9f23d79 commit 2e1fad5

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

apps/browser-extension-wallet/src/views/nami-mode/NamiView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { isKeyHashAddress } from '@cardano-sdk/wallet';
4242
import { BackgroundStorage } from '@lib/scripts/types';
4343
import { getWalletAccountsQtyString } from '@src/utils/get-wallet-count-string';
4444
import { useNetworkError } from '@hooks/useNetworkError';
45+
import { createHistoricalOwnInputResolver } from '@src/utils/own-input-resolver';
4546

4647
const { AVAILABLE_CHAINS, DEFAULT_SUBMIT_API } = config();
4748

@@ -237,7 +238,8 @@ export const NamiView = withDappContext((): React.ReactElement => {
237238
setDeletingWallet,
238239
chainHistoryProvider,
239240
protocolParameters: walletState?.protocolParameters,
240-
assetInfo: walletState?.assetInfo
241+
assetInfo: walletState?.assetInfo,
242+
createHistoricalOwnInputResolver
241243
}}
242244
>
243245
<CommonOutsideHandlesProvider

packages/nami/src/adapters/transactions.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable functional/prefer-immutable-types */
2-
import { useCallback, useEffect, useState } from 'react';
2+
import { useCallback, useEffect, useState, useMemo } from 'react';
33

44
import {
55
assetsMintedInspector,
@@ -515,20 +515,43 @@ export const useWalletTxs = () => {
515515
transactions,
516516
protocolParameters,
517517
assetInfo,
518+
createHistoricalOwnInputResolver,
518519
} = useOutsideHandles();
519520
const [txs, setTxs] = useState<(TxInfo | undefined)[]>();
520521
const rewardAccounts = useObservable(
521522
inMemoryWallet.delegation.rewardAccounts$,
522523
);
524+
const addresses = useObservable(inMemoryWallet.addresses$);
525+
526+
const { resolveInput } = useMemo(
527+
() =>
528+
createHistoricalOwnInputResolver({
529+
addresses,
530+
transactions,
531+
}),
532+
[addresses, transactions],
533+
);
523534

524535
const getTxInputsValueAndAddress = useCallback(
525-
async (inputs: Wallet.Cardano.HydratedTxIn[] | Wallet.Cardano.TxIn[]) =>
526-
await Wallet.getTxInputsValueAndAddress(
527-
inputs,
528-
chainHistoryProvider,
529-
inMemoryWallet,
530-
),
531-
[],
536+
async (inputs: Wallet.Cardano.HydratedTxIn[] | Wallet.Cardano.TxIn[]) => {
537+
const resolvedInputs = new Array<Wallet.Cardano.Utxo>();
538+
539+
for (const input of inputs) {
540+
const output = await resolveInput(input);
541+
output &&
542+
resolvedInputs.push([{ address: output.address, ...input }, output]);
543+
}
544+
return resolvedInputs.map(utxo => {
545+
const { address, value } = utxo[1];
546+
547+
return {
548+
...utxo[0],
549+
value,
550+
address,
551+
};
552+
});
553+
},
554+
[resolveInput],
532555
);
533556

534557
const fetchWalletActivities = useCallback(async () => {
@@ -558,7 +581,7 @@ export const useWalletTxs = () => {
558581
]);
559582

560583
useEffect(() => {
561-
if (!rewardAccounts || !transactions) return;
584+
if (!rewardAccounts || !transactions || !addresses) return;
562585
fetchWalletActivities();
563586
}, [
564587
fetchWalletActivities,

packages/nami/src/features/outside-handles-provider/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,16 @@ export interface OutsideHandlesContextValue {
123123
chainHistoryProvider: Wallet.ChainHistoryProvider;
124124
protocolParameters: Wallet.Cardano.ProtocolParameters;
125125
assetInfo: Wallet.Assets;
126+
createHistoricalOwnInputResolver: (
127+
props: Readonly<{
128+
transactions: {
129+
history: Wallet.Cardano.HydratedTx[];
130+
outgoing: {
131+
inFlight: Wallet.TxInFlight[];
132+
signed: Wallet.KeyManagement.WitnessedTx[];
133+
};
134+
};
135+
addresses: Wallet.WalletAddress[];
136+
}>,
137+
) => Wallet.Cardano.InputResolver;
126138
}

0 commit comments

Comments
 (0)