Skip to content
This repository was archived by the owner on Feb 8, 2026. It is now read-only.

Commit 08fb199

Browse files
Merge pull request #894 from synonymdev/fix-tx-details
fix(wallet): Fix Transaction Details
2 parents e881cfe + 8f70fca commit 08fb199

3 files changed

Lines changed: 64 additions & 44 deletions

File tree

src/screens/Settings/Advanced/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '../../../store/reselect/wallet';
1313
import type { SettingsScreenProps } from '../../../navigation/types';
1414
import { rescanAddresses } from '../../../utils/wallet';
15+
import { updateTransactions } from '../../../store/actions/wallet';
1516

1617
const typesDescriptions = {
1718
[EAddressType.p2wpkh]: 'Native Segwit',
@@ -68,6 +69,13 @@ const AdvancedSettings = ({
6869
onPress: async (): Promise<void> => {
6970
setRescanning(true);
7071
await rescanAddresses({ selectedWallet, selectedNetwork });
72+
await updateTransactions({
73+
scanAllAddresses: true,
74+
replaceStoredTransactions: true,
75+
selectedWallet,
76+
selectedNetwork,
77+
showNotification: false,
78+
});
7179
setRescanning(false);
7280
},
7381
},

src/store/actions/wallet.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,13 +621,23 @@ export interface ITransactionData {
621621
value: number;
622622
}
623623

624+
/**
625+
* Retrieves, formats & stores the transaction history for the selected wallet/network.
626+
* @param {boolean} [scanAllAddresses]
627+
* @param {boolean} [replaceStoredTransactions] Setting this to true will set scanAllAddresses to true as well.
628+
* @param {boolean} [showNotification]
629+
* @param {TWalletName} [selectedWallet]
630+
* @param {TAvailableNetworks} [selectedNetwork]
631+
*/
624632
export const updateTransactions = async ({
625633
scanAllAddresses = false,
634+
replaceStoredTransactions = false,
626635
showNotification = true,
627636
selectedWallet,
628637
selectedNetwork,
629638
}: {
630639
scanAllAddresses?: boolean;
640+
replaceStoredTransactions?: boolean;
631641
showNotification?: boolean;
632642
selectedWallet?: TWalletName;
633643
selectedNetwork?: TAvailableNetworks;
@@ -646,7 +656,7 @@ export const updateTransactions = async ({
646656
const history = await getAddressHistory({
647657
selectedNetwork,
648658
selectedWallet,
649-
scanAllAddresses,
659+
scanAllAddresses: scanAllAddresses || replaceStoredTransactions,
650660
});
651661
if (history.isErr()) {
652662
return err(history.error.message);
@@ -672,6 +682,20 @@ export const updateTransactions = async ({
672682
if (formatTransactionsResponse.isErr()) {
673683
return err(formatTransactionsResponse.error.message);
674684
}
685+
686+
if (replaceStoredTransactions) {
687+
// No need to check the existing txs. Update with the returned formatTransactionsResponse.
688+
dispatch({
689+
type: actions.UPDATE_TRANSACTIONS,
690+
payload: {
691+
transactions: formatTransactionsResponse.value,
692+
selectedNetwork,
693+
selectedWallet,
694+
},
695+
});
696+
updateSlashPayConfig({ sdk, selectedWallet, selectedNetwork });
697+
return ok(formatTransactionsResponse.value);
698+
}
675699
const formattedTransactions: IFormattedTransactions = {};
676700
const storedTransactions = currentWallet.transactions[selectedNetwork];
677701

src/utils/wallet/index.ts

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ export const getInputData = async ({
14851485
? [vout.scriptPubKey.address]
14861486
: [];
14871487
const value = vout.value;
1488-
const key = data.tx_hash;
1488+
const key = `${data.tx_hash}${vout.n}`;
14891489
inputData[key] = { addresses, value };
14901490
});
14911491
}
@@ -1543,38 +1543,36 @@ export const formatTransactions = async ({
15431543
let addresses = {} as IAddresses;
15441544
let changeAddresses = {} as IAddresses;
15451545

1546-
await Promise.all([
1547-
addressTypes.map((addressType) => {
1548-
// Check if addresses of this type have been generated. If not, skip.
1549-
if (Object.keys(currentAddresses[addressType])?.length > 0) {
1550-
addresses = { ...addresses, ...currentAddresses[addressType] };
1551-
}
1552-
}),
1553-
addressTypes.map((addressType) => {
1554-
// Check if change addresses of this type have been generated. If not, skip.
1555-
if (Object.keys(currentChangeAddresses[addressType])?.length > 0) {
1556-
changeAddresses = {
1557-
...changeAddresses,
1558-
...currentChangeAddresses[addressType],
1559-
};
1560-
}
1561-
}),
1562-
]);
1546+
addressTypes.map((addressType) => {
1547+
// Check if addresses of this type have been generated. If not, skip.
1548+
if (Object.keys(currentAddresses[addressType])?.length > 0) {
1549+
addresses = { ...addresses, ...currentAddresses[addressType] };
1550+
}
1551+
});
1552+
addressTypes.map((addressType) => {
1553+
// Check if change addresses of this type have been generated. If not, skip.
1554+
if (Object.keys(currentChangeAddresses[addressType])?.length > 0) {
1555+
changeAddresses = {
1556+
...changeAddresses,
1557+
...currentChangeAddresses[addressType],
1558+
};
1559+
}
1560+
});
15631561

1564-
const addressScriptHashes = Object.keys(addresses);
1565-
const changeAddressScriptHashes = Object.keys(changeAddresses);
1566-
const [addressArray, changeAddressArray] = await Promise.all([
1567-
addressScriptHashes.map((key) => {
1568-
return addresses[key].address;
1569-
}),
1570-
changeAddressScriptHashes.map((key) => {
1571-
return changeAddresses[key].address;
1572-
}),
1573-
]);
1562+
// Create combined address/change-address object for easier/faster reference later on.
1563+
const combinedAddressObj: { [key: string]: IAddress } = {};
1564+
[...Object.values(addresses), ...Object.values(changeAddresses)].map(
1565+
(data) => {
1566+
combinedAddressObj[data.address] = data;
1567+
},
1568+
);
15741569

15751570
const formattedTransactions: IFormattedTransactions = {};
1571+
transactions.map(async ({ data, result }) => {
1572+
if (!result?.txid) {
1573+
return;
1574+
}
15761575

1577-
transactions.map(({ data, result }) => {
15781576
let totalInputValue = 0; // Total value of all inputs.
15791577
let matchedInputValue = 0; // Total value of all inputs with addresses that belong to this wallet.
15801578
let totalOutputValue = 0; // Total value of all outputs.
@@ -1583,7 +1581,7 @@ export const formatTransactions = async ({
15831581

15841582
//Iterate over each input
15851583
const vin = result?.vin ?? [];
1586-
vin.map(({ txid, scriptSig }) => {
1584+
vin.map(({ txid, scriptSig, vout }) => {
15871585
//Push any OP_RETURN messages to messages array
15881586
try {
15891587
const asm = scriptSig.asm;
@@ -1593,14 +1591,11 @@ export const formatTransactions = async ({
15931591
}
15941592
} catch {}
15951593

1596-
const { addresses: _addresses, value } = inputData[txid];
1594+
const { addresses: _addresses, value } = inputData[`${txid}${vout}`];
15971595
totalInputValue = totalInputValue + value;
15981596
Array.isArray(_addresses) &&
15991597
_addresses.map((address) => {
1600-
if (
1601-
addressArray.includes(address) ||
1602-
changeAddressArray.includes(address)
1603-
) {
1598+
if (address in combinedAddressObj) {
16041599
matchedInputValue = matchedInputValue + value;
16051600
}
16061601
});
@@ -1617,19 +1612,12 @@ export const formatTransactions = async ({
16171612
totalOutputValue = totalOutputValue + value;
16181613
Array.isArray(_addresses) &&
16191614
_addresses.map((address) => {
1620-
if (
1621-
addressArray.includes(address) ||
1622-
changeAddressArray.includes(address)
1623-
) {
1615+
if (address in combinedAddressObj) {
16241616
matchedOutputValue = matchedOutputValue + value;
16251617
}
16261618
});
16271619
});
16281620

1629-
if (!result?.txid) {
1630-
return;
1631-
}
1632-
16331621
const txid = result.txid;
16341622
const type =
16351623
matchedInputValue > matchedOutputValue

0 commit comments

Comments
 (0)