Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(activity): fix status for boosted transfer #2090

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 52 additions & 53 deletions src/screens/Activity/ActivityDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ const OnchainActivityDetail = ({
const {
id,
txId,
transferTxId,
activityType,
txType,
value,
Expand All @@ -159,7 +160,9 @@ const OnchainActivityDetail = ({
const selectedNetwork = useAppSelector(selectedNetworkSelector);
const activityItems = useAppSelector(activityItemsSelector);
const boostedTransactions = useAppSelector(boostedTransactionsSelector);
const transfer = useAppSelector((state) => transferSelector(state, txId));
const transfer = useAppSelector((state) => {
return transferSelector(state, transferTxId);
});
const [txDetails, setTxDetails] = useState<ITransaction<ITxHash>['result']>();
const slashTagsUrl = useAppSelector((state) => {
return slashTagsUrlSelector(state, id);
Expand Down Expand Up @@ -211,19 +214,16 @@ const OnchainActivityDetail = ({
return boostedParents.length > 0;
}, [boostedParents.length]);

const handleBoostParentPress = useCallback(
(parentTxId) => {
const activityItem = activityItems.find((i) => {
return (
i.activityType === EActivityType.onchain && i.txId === parentTxId
);
});
if (activityItem) {
navigation.push('ActivityDetail', { id: activityItem.id });
}
},
[activityItems, navigation],
);
const handleBoostParentPress = (parentTxId): void => {
const activityItem = activityItems.find((i) => {
return i.activityType === EActivityType.onchain && i.txId === parentTxId;
});
if (activityItem) {
navigation.push('ActivityDetail', { id: activityItem.id });
} else {
onCopy(parentTxId);
}
};

const handleBoost = (): void => {
showBottomSheet('boostPrompt', { onchainActivityItem: item });
Expand Down Expand Up @@ -303,34 +303,6 @@ const OnchainActivityDetail = ({
<BodySSB color="brand">{t('activity_confirming')}</BodySSB>
</View>
);

if (isBoosted) {
status = (
<View style={styles.row}>
<TimerIconAlt style={styles.rowIcon} color="yellow" height={14} />
<BodySSB color="yellow">{t('activity_boosting')}</BodySSB>
</View>
);
}

if (confirmed) {
status = (
<View style={styles.row}>
<CheckCircleIcon style={styles.rowIcon} color="green" />
<BodySSB color="green">{t('activity_confirmed')}</BodySSB>
</View>
);
}

if (activityType === EActivityType.onchain && !exists) {
status = (
<View style={styles.row}>
<XIcon style={styles.rowIcon} color="red" height={18} width={16} />
<BodySSB color="red">{t('activity_removed')}</BodySSB>
</View>
);
}

let icon = isSend ? (
<ThemedView style={styles.icon} color="brand16">
<SendIcon height={19} color="brand" />
Expand Down Expand Up @@ -363,6 +335,33 @@ const OnchainActivityDetail = ({
);
}

if (isBoosted) {
status = (
<View style={styles.row}>
<TimerIconAlt style={styles.rowIcon} color="yellow" height={14} />
<BodySSB color="yellow">{t('activity_boosting')}</BodySSB>
</View>
);
}

if (confirmed) {
status = (
<View style={styles.row}>
<CheckCircleIcon style={styles.rowIcon} color="green" />
<BodySSB color="green">{t('activity_confirmed')}</BodySSB>
</View>
);
}

if (activityType === EActivityType.onchain && !exists) {
status = (
<View style={styles.row}>
<XIcon style={styles.rowIcon} color="red" height={18} width={16} />
<BodySSB color="red">{t('activity_removed')}</BodySSB>
</View>
);
}

return (
<>
<Money
Expand Down Expand Up @@ -626,20 +625,20 @@ const OnchainActivityDetail = ({

return (
<View key={parent} style={styles.sectionContainer}>
<Section
title={title}
value={
<TouchableOpacity
activeOpacity={0.7}
onPress={(): void => {
handleBoostParentPress(parent);
}}>
<TouchableOpacity
activeOpacity={0.7}
onPress={(): void => {
handleBoostParentPress(parent);
}}>
<Section
title={title}
value={
<BodySSB numberOfLines={1} ellipsizeMode="middle">
{parent}
</BodySSB>
</TouchableOpacity>
}
/>
}
/>
</TouchableOpacity>
</View>
);
})}
Expand Down
51 changes: 19 additions & 32 deletions src/screens/Activity/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ import {
import { useAppSelector } from '../../hooks/redux';
import { useProfile } from '../../hooks/slashtags';
import { useFeeText } from '../../hooks/fees';
import {
ETransferStatus,
TTransferToSavings,
TTransferToSpending,
} from '../../store/types/wallet';
import { ETransferStatus, ETransferType } from '../../store/types/wallet';
import { slashTagsUrlSelector } from '../../store/reselect/metadata';
import { getDurationForBlocks, truncate } from '../../utils/helpers';
import { getActivityItemDate } from '../../utils/activity';
Expand Down Expand Up @@ -90,8 +86,7 @@ const OnchainListItem = ({
}): ReactElement => {
const { t } = useTranslation('wallet');
const {
id,
txId,
transferTxId,
txType,
value,
fee,
Expand All @@ -105,12 +100,9 @@ const OnchainListItem = ({
const { shortRange: feeRateDescription } = useFeeText(feeRate);
const isSend = txType === EPaymentType.sent;

const transferToSpending = useAppSelector((state) => {
return transferSelector(state, txId);
}) as TTransferToSpending;
const transferToSavings = useAppSelector((state) => {
return transferSelector(state, id);
}) as TTransferToSavings;
const transfer = useAppSelector((state) => {
return transferSelector(state, transferTxId);
});

let title = t(isSend ? 'activity_sent' : 'activity_received');
const amount = isSend ? value + fee : value;
Expand All @@ -132,34 +124,29 @@ const OnchainListItem = ({
description = t('activity_low_fee');
}

if (transferToSavings && !transferToSpending) {
if (transfer) {
title = t('activity_transfer');
if (transferToSavings.status === ETransferStatus.done) {
description = t('activity_transfer_savings_done');
} else {
const duration = getDurationForBlocks(transferToSavings.confirmsIn);
description = t('activity_transfer_savings_pending', { duration });
}
icon = (
<ThemedView style={styles.icon} color="brand16">
<TransferIcon color="brand" />
</ThemedView>
);
}

if (transferToSpending) {
title = t('activity_transfer');
if (confirmed) {
description = t('activity_transfer_spending_done');
if (transfer.type === ETransferType.open) {
if (confirmed) {
description = t('activity_transfer_spending_done');
} else {
const duration = getDurationForBlocks(1);
description = t('activity_transfer_spending_pending', { duration });
}
} else {
const duration = getDurationForBlocks(1);
description = t('activity_transfer_spending_pending', { duration });
if (transfer.status === ETransferStatus.done) {
description = t('activity_transfer_savings_done');
} else {
const duration = getDurationForBlocks(transfer.confirmsIn);
description = t('activity_transfer_savings_pending', { duration });
}
}
icon = (
<ThemedView style={styles.icon} color="brand16">
<TransferIcon color="brand" />
</ThemedView>
);
}

return (
Expand Down
2 changes: 1 addition & 1 deletion src/store/reselect/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const pendingTransfersSelector = createSelector(
* Returns transfers for the currently selected wallet.
*/
export const transferSelector = createSelector(
[walletState, (_state, txId: string): string => txId],
[walletState, (_state, txId?: string): string | undefined => txId],
(wallet, txId) => {
const { selectedWallet, selectedNetwork } = wallet;
const transfers = wallet.wallets[selectedWallet].transfers[selectedNetwork];
Expand Down
1 change: 1 addition & 0 deletions src/store/types/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type TOnchainActivityItem = {
exists: boolean; // Used to determine if the transaction exists on the blockchain or if it was reorg'd/bumped from the mempool.
confirmTimestamp?: number;
channelId?: string;
transferTxId?: string;
};

export type TLightningActivityItem = {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/activity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ export const onChainTransactionToActivityItem = async ({

return {
id: transfer ? transfer.txId : transaction.txid,
exists: transaction?.exists ?? true,
exists: transaction.exists ?? true,
activityType: EActivityType.onchain,
txType: transaction.type,
txId: transaction.txid,
transferTxId: transfer?.txId,
value: btcToSats(Math.abs(amount)),
fee: btcToSats(Math.abs(transaction.fee)),
feeRate: Math.round(transaction.satsPerByte),
Expand Down
8 changes: 4 additions & 4 deletions src/utils/boost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ export const formatBoostedActivityItems = ({
const formattedItems: TOnchainActivityItem[] = [];

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

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

Expand Down Expand Up @@ -240,13 +240,13 @@ export const calculateBoostTransactionValue = ({
includeFee?: boolean;
}): number => {
const boostedTransaction = Object.values(boostedTransactions).find(
(tx) => tx.childTransaction === currentActivityItem.id,
(tx) => tx.childTransaction === currentActivityItem.txId,
);
if (!boostedTransaction) {
return currentActivityItem.value;
}
const rootParent = getRootParentActivity({
txId: currentActivityItem.id,
txId: currentActivityItem.txId,
items,
boostedTransactions,
});
Expand Down
Loading