Skip to content

Commit

Permalink
[WALL] [Fix] Rostislav / WALL-2754 / Temporary workaround for BE `sta…
Browse files Browse the repository at this point in the history
…tement` response lacking `to` and `from` for Deriv X accounts (deriv-com#11743)

* fix: an atrocious solution

* refactor: readibility

* refactor: remove a bit of prev code

---------

Co-authored-by: George Usynin <[email protected]>
  • Loading branch information
rostislav-deriv and heorhi-deriv authored Nov 24, 2023
1 parent 9099e82 commit 50fe6f0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/api/src/hooks/useTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const useTransactions = () => {
},
payload: {
action_type: filter,
// TODO: remove this once backend adds `to` and `from` for Deriv X transfers
description: 1,
},
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import { WalletText } from '../../../../../../components/Base';
import { THooks } from '../../../../../../types';
import { TransactionsCompletedRowAccountDetails } from './components/TransactionsCompletedRowAccountDetails';
Expand All @@ -12,6 +12,24 @@ type TProps = {
};

const TransactionsCompletedRow: React.FC<TProps> = ({ accounts, transaction, wallet }) => {
// TODO: remove this once backend adds `to` and `from` for Deriv X transfers
const dxtradeToFrom = useMemo(() => {
if (
transaction?.action_type !== 'transfer' ||
!transaction.longcode ||
!transaction.longcode.includes('Deriv X')
)
return null;
const longcodeMessageTokens = transaction.longcode.split(' ');
const direction = longcodeMessageTokens[1];
const dxtradeLoginid = longcodeMessageTokens.find(token => token.startsWith('DX'));
return {
from: { loginid: wallet.loginid },
to: { loginid: wallet.loginid },
...(direction && { [direction]: { loginid: dxtradeLoginid } }),
};
}, [transaction?.action_type, transaction.longcode, wallet.loginid]);

if (!transaction.action_type || !transaction.amount) return null;

const displayCurrency = wallet?.currency_config?.display_code || 'USD';
Expand All @@ -31,11 +49,12 @@ const TransactionsCompletedRow: React.FC<TProps> = ({ accounts, transaction, wal
) : (
<TransactionsCompletedRowTransferAccountDetails
accounts={accounts}
direction={transaction.from?.loginid === wallet?.loginid ? 'to' : 'from'}
direction={(transaction.from ?? dxtradeToFrom?.from)?.loginid === wallet?.loginid ? 'to' : 'from'}
loginid={
[transaction.from?.loginid, transaction.to?.loginid].find(
loginid => loginid !== wallet?.loginid
) ?? ''
[
transaction.from?.loginid ?? dxtradeToFrom?.from.loginid,
transaction.to?.loginid ?? dxtradeToFrom?.to.loginid,
].find(loginid => loginid !== wallet?.loginid) ?? ''
}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type TProps = {
const TransactionsCompletedRowTransferAccountDetails: React.FC<TProps> = ({ accounts, direction, loginid }) => {
const wallet = accounts.wallets?.find(account => account.loginid === loginid);
const dtradeAccount = accounts.dtrade?.find(account => account.loginid === loginid);
const dxtradeAccount = accounts.dxtrade?.find(account => account.login === loginid);
const dxtradeAccount = accounts.dxtrade?.find(account => account.account_id === loginid);
// TODO: remove the `replace` calls once backend resolves `statement` and `mt5_login_list` accounts `loginid` inconsistency
const mt5Account = accounts.mt5?.find(
account => account.login?.replace(/^\D+/g, '') === loginid.replace(/^\D+/g, '')
Expand Down

0 comments on commit 50fe6f0

Please sign in to comment.