Skip to content

Commit

Permalink
fix(feedV2): fix missing title, subtitle, localAmount for deposit and…
Browse files Browse the repository at this point in the history
… withdraw (#6200)

### Description

Follow up to #6189 with small
bugs that I noticed.

### Test plan

- Updated tests

### Related issues

- Part of RET-1204

### Backwards compatibility

Yes

### Network scalability

If a new NetworkId and/or Network are added in the future, the changes
in this PR will:

- [x] Continue to work without code changes, OR trigger a compilation
error (guaranteeing we find it when a new network is added)
  • Loading branch information
jeanregisser authored Oct 31, 2024
1 parent 12210f7 commit bfdea5e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 28 deletions.
2 changes: 1 addition & 1 deletion locales/base/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,7 @@
"crossChainSwapTransactionLabel": "Cross-chain",
"depositTitle": "Deposited",
"depositSubtitle": "to {{txAppName}} Pool",
"depositSubtitle_noTxAppName": "to unknown pool",
"depositSubtitle_noTxAppName": "to unknown app",
"withdrawTitle": "Withdrew",
"withdrawSubtitle": "from {{txAppName}} Pool",
"withdrawSubtitle_noTxAppName": "from unknown app",
Expand Down
16 changes: 8 additions & 8 deletions src/transactions/feed/DepositOrWithdrawFeedItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ describe('DepositOrWithdrawFeedItem', () => {
expect(getByText('transactionFeed.depositSubtitle, {"txAppName":"Some Dapp"}')).toBeTruthy()
})

it('does not display app name when not available', () => {
const transactionWithoutProvider = {
...depositTransaction,
appName: undefined,
}

it('displays when app name is not available', () => {
const { queryByText } = render(
<Provider store={store}>
<DepositOrWithdrawFeedItem transaction={transactionWithoutProvider} />
<DepositOrWithdrawFeedItem
transaction={{
...depositTransaction,
appName: undefined,
}}
/>
</Provider>
)

expect(queryByText('transactionFeed.depositSubtitle, {"txAppName":"Some Dapp"}')).toBeNull()
expect(queryByText('transactionFeed.depositSubtitle, {"context":"noTxAppName"}')).toBeTruthy()
})

it('should fire analytic event on tap', () => {
Expand Down
16 changes: 7 additions & 9 deletions src/transactions/feed/DepositOrWithdrawFeedItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,9 @@ function Description({ transaction }: DescriptionProps) {
<Text style={styles.title} testID={'DepositOrWithdrawFeedItem/title'} numberOfLines={1}>
{title}
</Text>
{!!txAppName && (
<Text
style={styles.subtitle}
testID={'DepositOrWithdrawFeedItem/subtitle'}
numberOfLines={1}
>
{subtitle}
</Text>
)}
<Text style={styles.subtitle} testID={'DepositOrWithdrawFeedItem/subtitle'} numberOfLines={1}>
{subtitle}
</Text>
</View>
)
}
Expand All @@ -67,15 +61,18 @@ interface AmountDisplayProps {

function AmountDisplay({ transaction, isLocal }: AmountDisplayProps) {
let amountValue
let localAmount
let tokenId

switch (transaction.type) {
case TokenTransactionTypeV2.Deposit:
amountValue = new BigNumber(-transaction.outAmount.value)
localAmount = transaction.outAmount.localAmount
tokenId = transaction.outAmount.tokenId
break
case TokenTransactionTypeV2.Withdraw:
amountValue = new BigNumber(transaction.inAmount.value)
localAmount = transaction.inAmount.localAmount
tokenId = transaction.inAmount.tokenId
break
}
Expand All @@ -90,6 +87,7 @@ function AmountDisplay({ transaction, isLocal }: AmountDisplayProps) {
return (
<TokenDisplay
amount={amountValue}
localAmount={localAmount}
tokenId={tokenId}
showLocalAmount={isLocal}
showSymbol={true}
Expand Down
36 changes: 36 additions & 0 deletions src/transactions/feed/TransactionDetailsScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ describe('TransactionDetailsScreen', () => {

function depositTransaction({
status = TransactionStatus.Complete,
...rest
}: Partial<DepositOrWithdraw>): DepositOrWithdraw {
return {
type: TokenTransactionTypeV2.Deposit,
Expand All @@ -596,15 +597,18 @@ describe('TransactionDetailsScreen', () => {
tokenId: mockCusdTokenId,
},
status,
...rest,
}
}

function withdrawTransaction({
status = TransactionStatus.Complete,
...rest
}: Partial<DepositOrWithdraw>): DepositOrWithdraw {
return {
...depositTransaction({ status }),
type: TokenTransactionTypeV2.Withdraw,
...rest,
}
}

Expand Down Expand Up @@ -648,6 +652,38 @@ describe('TransactionDetailsScreen', () => {
expect(getByText('transactionDetailsActions.showCompletedTransactionDetails')).toBeTruthy()
})

it('should display app name', () => {
const { getByText } = renderScreen({
transaction: depositTransaction({ appName: 'Aave' }),
storeOverrides: {
tokens: {
tokenBalances: mockTokenBalances,
},
},
})

expect(
getByText('transactionDetails.depositSubtitle, {"txAppName":"Aave","tokenSymbol":"cUSD"}')
).toBeTruthy()
})

it('should display when app name is not available', () => {
const { getByText } = renderScreen({
transaction: depositTransaction({ appName: undefined }),
storeOverrides: {
tokens: {
tokenBalances: mockTokenBalances,
},
},
})

expect(
getByText(
'transactionDetails.depositSubtitle, {"context":"noTxAppName","tokenSymbol":"cUSD"}'
)
).toBeTruthy()
})

it('renders swap details for deposit with swap', () => {
const transactionWithSwap = {
...depositTransaction({ status: TransactionStatus.Complete }),
Expand Down
4 changes: 4 additions & 0 deletions src/transactions/feed/TransactionDetailsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ function useHeaderTitle(transaction: TokenTransaction) {
return t('swapScreen.title')
case TokenTransactionTypeV2.Approval:
return t('transactionFeed.approvalTransactionTitle')
case TokenTransactionTypeV2.Deposit:
return t('transactionFeed.depositTitle')
case TokenTransactionTypeV2.Withdraw:
return t('transactionFeed.withdrawTitle')
case TokenTransactionTypeV2.ClaimReward:
return t('transactionFeed.claimRewardTitle')
case TokenTransactionTypeV2.EarnWithdraw:
Expand Down
17 changes: 7 additions & 10 deletions src/transactions/feed/detailContent/DepositOrWithdrawContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,12 @@ export function DepositOrWithdrawContent({ transaction }: DepositOrWithdrawConte
return (
<>
<Text style={styles.detailsTitle}>{t('transactionDetails.descriptionLabel')}</Text>
{!!txAppName && (
<Text style={styles.detailsSubtitle}>
{t(
isDeposit
? 'transactionDetails.depositSubtitle'
: 'transactionDetails.withdrawSubtitle',
{ context: !txAppName ? 'noTxAppName' : undefined, txAppName, tokenSymbol }
)}
</Text>
)}
<Text style={styles.detailsSubtitle}>
{t(
isDeposit ? 'transactionDetails.depositSubtitle' : 'transactionDetails.withdrawSubtitle',
{ context: !txAppName ? 'noTxAppName' : undefined, txAppName, tokenSymbol }
)}
</Text>
<RowDivider />
<View style={styles.amountContainer}>
<View>
Expand All @@ -66,6 +62,7 @@ export function DepositOrWithdrawContent({ transaction }: DepositOrWithdrawConte
</View>
<TokenDisplay
amount={amount.value}
localAmount={amount.localAmount}
tokenId={amount.tokenId}
style={styles.amountSubtitle}
/>
Expand Down

0 comments on commit bfdea5e

Please sign in to comment.