Skip to content

Commit

Permalink
fix(transfer): activity for transfer to savings boosts (#2421)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwltr authored Jan 8, 2025
1 parent 94798cc commit ae22219
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/screens/Activity/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const OnchainListItem = ({
if (transfer) {
title = t('activity_transfer');
icon = (
<ThemedView style={styles.icon} color="brand16">
<ThemedView style={styles.icon} color="brand16" testID="TransferIcon">
<TransferIcon color="brand" />
</ThemedView>
);
Expand Down
8 changes: 6 additions & 2 deletions src/screens/Wallets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RefreshControl, ScrollView } from 'react-native-gesture-handler';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { useTranslation } from 'react-i18next';

import { View as ThemedView } from '../../styles/components';
import { useBalance } from '../../hooks/wallet';
import useColors from '../../hooks/colors';
import { useAppDispatch, useAppSelector } from '../../hooks/redux';
Expand Down Expand Up @@ -107,7 +108,7 @@ const Wallets = ({ navigation, onFocus }: Props): ReactElement => {
Object.keys(widgets).length > 0;

return (
<>
<ThemedView style={styles.root}>
<SafeAreaInset type="top" />
<View style={[styles.header, { top: insets.top }]}>
<Header />
Expand Down Expand Up @@ -154,11 +155,14 @@ const Wallets = ({ navigation, onFocus }: Props): ReactElement => {
)}
</ScrollView>
</DetectSwipe>
</>
</ThemedView>
);
};

const styles = StyleSheet.create({
root: {
flex: 1,
},
header: {
position: 'absolute',
left: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/store/utils/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const updateOnChainActivityList = async (): Promise<Result<string>> => {

const transactions = currentWallet.transactions[selectedNetwork];
const promises = Object.values(transactions).map(async (tx) => {
return await onChainTransactionToActivityItem({ transaction: tx });
return onChainTransactionToActivityItem({ transaction: tx });
});
const activityItems = await Promise.all(promises);

Expand Down
6 changes: 2 additions & 4 deletions src/utils/activity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ export const onChainTransactionToActivityItem = async ({
}: {
transaction: IFormattedTransaction;
}): Promise<TOnchainActivityItem> => {
const { type, value, fee } = transaction;
const transfer = await getTransferForTx(transaction);

// subtract fee from amount if applicable
const amount =
transaction.type === 'sent'
? transaction.value + transaction.fee
: transaction.value;
const amount = type === 'sent' ? value + fee : value;

return {
id: transaction.txid,
Expand Down
26 changes: 4 additions & 22 deletions src/utils/boost.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IBoostedTransactions, Wallet as TWallet } from 'beignet';

import { getActivityStore, getWalletStore } from '../store/helpers';
import { IActivityItem, TOnchainActivityItem } from '../store/types/activity';
import { getWalletStore } from '../store/helpers';
import { TOnchainActivityItem } from '../store/types/activity';
import { TWalletName } from '../store/types/wallet';
import { EAvailableNetwork } from './networks';
import {
Expand Down Expand Up @@ -85,26 +85,6 @@ const getRootParentActivity = async ({
return filteredItem;
};

/**
* Returns an array of activity items for the provided array of parent txids.
* CURRENTLY UNUSED
* // TODO: Migrate to Beignet
* @param {string[]} [parents]
* @param {IActivityItem[]} [items]
*/
export const getParentsActivity = ({
parents = [],
items = [],
}: {
parents?: string[];
items?: IActivityItem[];
}): IActivityItem[] => {
if (!items) {
items = getActivityStore().items;
}
return items.filter((i) => parents.includes(i.id));
};

/**
* Loop through activity items and format them to be displayed as boosted if applicable.
* @param {TOnchainActivityItem[]} [items]
Expand Down Expand Up @@ -172,6 +152,8 @@ export const formatBoostedActivityItems = async ({
fee: rootParent.fee + item.fee,
address: rootParent.address,
isBoosted: true,
isTransfer: rootParent.isTransfer,
transferTxId: rootParent.transferTxId,
});
}

Expand Down

0 comments on commit ae22219

Please sign in to comment.