Skip to content

Commit

Permalink
fix(activity): wrong txId in some places (#1903)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwltr authored May 29, 2024
1 parent daad467 commit 4192ea7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
28 changes: 15 additions & 13 deletions src/screens/Activity/ActivityDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const OnchainActivityDetail = ({
return;
}

getTransactions({ txHashes: [{ tx_hash: id }] }).then((txResponse) => {
getTransactions({ txHashes: [{ tx_hash: txId }] }).then((txResponse) => {
if (txResponse.isErr()) {
showToast({
type: 'warning',
Expand All @@ -191,29 +191,33 @@ const OnchainActivityDetail = ({
const data = txData[0].result;
setTxDetails(data);
});
}, [id, activityType, extended, selectedNetwork, txDetails, t]);
}, [txId, activityType, extended, selectedNetwork, txDetails, t]);

const showBoost = useMemo(() => {
if (confirmed || isBoosted) {
return false;
}
return canBoost(id).canBoost;
}, [confirmed, isBoosted, id]);
return canBoost(txId).canBoost;
}, [confirmed, isBoosted, txId]);

const boostedParents = useMemo(() => {
return getBoostedTransactionParents({
txid: id,
txId,
boostedTransactions,
});
}, [boostedTransactions, id]);
}, [boostedTransactions, txId]);

const hasBoostedParents = useMemo(() => {
return boostedParents.length > 0;
}, [boostedParents.length]);

const handleBoostParentPress = useCallback(
(parentTxId) => {
const activityItem = activityItems.find((i) => i.id === parentTxId);
const activityItem = activityItems.find((i) => {
return (
i.activityType === EActivityType.onchain && i.txId === parentTxId
);
});
if (activityItem) {
navigation.push('ActivityDetail', { id: activityItem.id });
}
Expand Down Expand Up @@ -250,7 +254,7 @@ const OnchainActivityDetail = ({
}
};

const blockExplorerUrl = getBlockExplorerLink(id);
const blockExplorerUrl = getBlockExplorerLink(txId);

const handleExplore = (): void => {
navigation.push('ActivityDetail', {
Expand Down Expand Up @@ -589,10 +593,8 @@ const OnchainActivityDetail = ({
<Section
title={t('activity_input', { count: txDetails.vin.length })}
value={txDetails.vin.map((v) => {
const txid = v.txid;
const vout = v.vout;
const i = txid + ':' + vout;
return <BodySSB key={i}>{i}</BodySSB>;
const input = `${v.txid}:${v.vout}`;
return <BodySSB key={input}>{input}</BodySSB>;
})}
/>
</View>
Expand Down Expand Up @@ -626,7 +628,7 @@ const OnchainActivityDetail = ({
onPress={(): void => {
handleBoostParentPress(parent);
}}>
<BodySSB numberOfLines={1} ellipsizeMode={'middle'}>
<BodySSB numberOfLines={1} ellipsizeMode="middle">
{parent}
</BodySSB>
</TouchableOpacity>
Expand Down
34 changes: 17 additions & 17 deletions src/utils/boost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ export const getBoostedTransactions = ({

/**
* Returns an array of parents for a boosted transaction id.
* @param {string} txid
* @param {string} txId
* @param {IBoostedTransactions} [boostedTransactions]
* @param {TWalletName} [selectedWallet]
* @param {EAvailableNetwork} [selectedNetwork]
* @returns {string[]}
*/
export const getBoostedTransactionParents = ({
txid,
txId,
boostedTransactions,
selectedWallet = getSelectedWallet(),
selectedNetwork = getSelectedNetwork(),
}: {
txid: string;
txId: string;
boostedTransactions?: IBoostedTransactions;
selectedWallet?: TWalletName;
selectedNetwork?: EAvailableNetwork;
Expand All @@ -49,28 +49,28 @@ export const getBoostedTransactionParents = ({
});
}
const boostObj = Object.values(boostedTransactions).find((boostObject) => {
return boostObject.childTransaction === txid;
return boostObject.childTransaction === txId;
});

return boostObj?.parentTransactions ?? [];
};

/**
* Determines if a given txid has any boosted parents.
* Determines if a given txId has any boosted parents.
* // TODO: Migrate to Beignet
* @param {string} txid
* @param {string} txId
* @param {IBoostedTransactions} [boostedTransactions]
* @param {TWalletName} [selectedWallet]
* @param {EAvailableNetwork} [selectedNetwork]
* @returns {boolean}
*/
export const hasBoostedParents = ({
txid,
txId,
boostedTransactions,
selectedWallet = getSelectedWallet(),
selectedNetwork = getSelectedNetwork(),
}: {
txid: string;
txId: string;
boostedTransactions?: IBoostedTransactions;
selectedWallet?: TWalletName;
selectedNetwork?: EAvailableNetwork;
Expand All @@ -82,29 +82,29 @@ export const hasBoostedParents = ({
});
}
const boostedParents = getBoostedTransactionParents({
txid,
txId,
boostedTransactions,
});
return boostedParents.length > 0;
};

/**
* Returns the initially boosted transaction's activity item for a given txid.
* @param {string} txid
* Returns the initially boosted transaction's activity item for a given txId.
* @param {string} txId
* @param {IActivityItem[]} [items]
* @param {IBoostedTransactions} [boostedTransactions]
* @param {TWalletName} [selectedWallet]
* @param {EAvailableNetwork} [selectedNetwork]
* @returns {TOnchainActivityItem|undefined}
*/
export const getRootParentActivity = ({
txid,
txId,
items,
boostedTransactions,
selectedWallet = getSelectedWallet(),
selectedNetwork = getSelectedNetwork(),
}: {
txid: string;
txId: string;
items: TOnchainActivityItem[];
boostedTransactions?: IBoostedTransactions;
selectedWallet?: TWalletName;
Expand All @@ -117,7 +117,7 @@ export const getRootParentActivity = ({
});
}
const boostedParents = getBoostedTransactionParents({
txid,
txId,
boostedTransactions,
});
if (!boostedParents.length) {
Expand Down Expand Up @@ -169,15 +169,15 @@ export const formatBoostedActivityItems = ({
const formattedItems: TOnchainActivityItem[] = [];

items.forEach((item) => {
const txid = item.id;
const txId = item.id;

// if boosted tx don't add for now
if (item.id in boostedTransactions) {
return;
}

const rootParent = getRootParentActivity({
txid,
txId,
items,
boostedTransactions,
selectedWallet,
Expand Down Expand Up @@ -246,7 +246,7 @@ export const calculateBoostTransactionValue = ({
return currentActivityItem.value;
}
const rootParent = getRootParentActivity({
txid: currentActivityItem.id,
txId: currentActivityItem.id,
items,
boostedTransactions,
});
Expand Down

0 comments on commit 4192ea7

Please sign in to comment.