forked from deriv-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
farhan/feat: Cashier Completed Transactions (deriv-com#10566)
* feat: cashier transactions * chore: rename components and invalidate query * chore: move effects down to child components * refactor: filter logics * fix: status and filter logics
- Loading branch information
1 parent
81950f7
commit 3af7eaf
Showing
22 changed files
with
359 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/wallets/src/features/cashier/flows/WalletTransactions/WalletTransactions.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
.wallets-transactions { | ||
width: 70vw; | ||
|
||
@include mobile { | ||
width: 100%; | ||
} | ||
|
||
&__header { | ||
display: flex; | ||
gap: 16px; | ||
|
86 changes: 67 additions & 19 deletions
86
packages/wallets/src/features/cashier/flows/WalletTransactions/WalletTransactions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ns/WalletTransactionsScreens/WalletTransactionsCompleted/WalletTransactionsCompleted.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.wallets-transactions-completed { | ||
position: relative; | ||
|
||
&__group-title { | ||
width: 74px; | ||
height: 14px; | ||
color: var(--system-light-3-less-prominent-text, #999); | ||
text-align: right; | ||
|
||
/* desktop/extra small/XS - regular */ | ||
font-size: 10px; | ||
font-style: normal; | ||
font-weight: 400; | ||
line-height: 14px; /* 140% */ | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...ens/WalletTransactionsScreens/WalletTransactionsCompleted/WalletTransactionsCompleted.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React, { useCallback, useEffect } from 'react'; | ||
import moment from 'moment'; | ||
import { useTransactions } from '@deriv/api'; | ||
import { TSocketRequestPayload } from '@deriv/api/types'; | ||
import { WalletTransactionsCompletedRow } from '../WalletTransactionsCompletedRow'; | ||
import { WalletTransactionsNoDataState } from '../WalletTransactionsNoDataState'; | ||
import { WalletTransactionsTable } from '../WalletTransactionsTable'; | ||
import './WalletTransactionsCompleted.scss'; | ||
|
||
type TFilter = NonNullable<TSocketRequestPayload<'statement'>['payload']>['action_type']; | ||
|
||
type TProps = { | ||
filter?: TFilter; | ||
}; | ||
|
||
const WalletTransactionsCompleted: React.FC<TProps> = ({ filter }) => { | ||
const { data, fetchNextPage, isFetching, setFilter } = useTransactions(); | ||
|
||
const fetchMoreOnBottomReached = useCallback( | ||
(containerRefElement?: HTMLDivElement | null) => { | ||
if (containerRefElement) { | ||
const { clientHeight, scrollHeight, scrollTop } = containerRefElement; | ||
//once the user has scrolled within 300px of the bottom of the table, fetch more data if there is any | ||
if (scrollHeight - scrollTop - clientHeight < 300 && !isFetching) { | ||
fetchNextPage(); | ||
} | ||
} | ||
}, | ||
[fetchNextPage, isFetching] | ||
); | ||
|
||
useEffect(() => { | ||
setFilter(filter); | ||
}, [filter]); // eslint-disable-line react-hooks/exhaustive-deps | ||
|
||
if (!data) return <WalletTransactionsNoDataState />; | ||
|
||
return ( | ||
<div> | ||
<WalletTransactionsTable | ||
columns={[ | ||
{ | ||
accessorFn: row => | ||
row.transaction_time && moment.unix(row.transaction_time).format('DD MMM YYYY'), | ||
accessorKey: 'date', | ||
header: 'Date', | ||
}, | ||
]} | ||
data={data} | ||
fetchMore={fetchMoreOnBottomReached} | ||
groupBy={['date']} | ||
rowGroupRender={transaction => ( | ||
<p className='wallets-transactions-completed__group-title'> | ||
{transaction.transaction_time && | ||
moment.unix(transaction.transaction_time).format('DD MMM YYYY')} | ||
</p> | ||
)} | ||
rowRender={transaction => <WalletTransactionsCompletedRow transaction={transaction} />} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default WalletTransactionsCompleted; |
1 change: 1 addition & 0 deletions
1
...c/features/cashier/screens/WalletTransactionsScreens/WalletTransactionsCompleted/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as WalletTransactionsCompleted } from './WalletTransactionsCompleted'; |
67 changes: 67 additions & 0 deletions
67
...letTransactionsScreens/WalletTransactionsCompletedRow/WalletTransactionsCompletedRow.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
.wallets-transactions-completed-row { | ||
display: flex; | ||
padding: 16px; | ||
justify-content: space-between; | ||
align-items: center; | ||
border-top: 1px solid var(--system-light-3-border, #e5e5e5); | ||
|
||
&-content { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
|
||
&__account-details { | ||
display: flex; | ||
width: max-content; | ||
gap: 8px; | ||
|
||
&__action-type { | ||
color: var(--system-light-3-less-prominent-text, #999); | ||
|
||
/* desktop/small/S - regular */ | ||
font-size: 12px; | ||
font-style: normal; | ||
font-weight: 400; | ||
line-height: 18px; /* 150% */ | ||
text-transform: capitalize; | ||
} | ||
|
||
&__wallet-name { | ||
color: var(--system-light-1-prominent-text, #333); | ||
|
||
/* desktop/small/S - bold */ | ||
font-size: 12px; | ||
font-style: normal; | ||
font-weight: 700; | ||
line-height: 18px; /* 150% */ | ||
} | ||
} | ||
|
||
&__transaction-details { | ||
&__amount { | ||
color: var(--status-light-success, #4bb4b3); | ||
text-align: right; | ||
|
||
/* desktop/small/S - bold */ | ||
font-size: 12px; | ||
font-style: normal; | ||
font-weight: 700; | ||
line-height: 18px; /* 150% */ | ||
|
||
&--negative { | ||
color: var(--status-light-danger, #ec3f3f); | ||
} | ||
} | ||
|
||
&__balance { | ||
color: var(--system-light-3-less-prominent-text, #999); | ||
text-align: right; | ||
|
||
/* desktop/extra small/XS - regular */ | ||
font-size: 10px; | ||
font-style: normal; | ||
font-weight: 400; | ||
line-height: 14px; /* 140% */ | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...lletTransactionsScreens/WalletTransactionsCompletedRow/WalletTransactionsCompletedRow.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useMemo } from 'react'; | ||
import { useActiveWalletAccount, useTransactions } from '@deriv/api'; | ||
import { WalletCurrencyCard } from '../../../../../components/WalletCurrencyCard'; | ||
import './WalletTransactionsCompletedRow.scss'; | ||
|
||
type TProps = { | ||
transaction: NonNullable<ReturnType<typeof useTransactions>['data']>[number]; | ||
}; | ||
|
||
const WalletTransactionsCompletedRow: React.FC<TProps> = ({ transaction }) => { | ||
const { data } = useActiveWalletAccount(); | ||
const displayCode = useMemo(() => data?.currency_config?.display_code || 'USD', [data]); | ||
|
||
const formattedAmount = useMemo(() => { | ||
if (!transaction?.amount) return; | ||
|
||
if (transaction.amount > 0) { | ||
return `+${transaction.amount}`; | ||
} | ||
return transaction.amount; | ||
}, [transaction]); | ||
|
||
return ( | ||
<div className='wallets-transactions-completed-row'> | ||
<div className='wallets-transactions-completed-row__account-details'> | ||
<WalletCurrencyCard currency={data?.currency || 'USD'} isDemo={data?.is_virtual} size='md' /> | ||
<div> | ||
<p className='wallets-transactions-completed-row__account-details__action-type'> | ||
{transaction.action_type} | ||
</p> | ||
<p className='wallets-transactions-completed-row__account-details__wallet-name'> | ||
{displayCode} Wallet | ||
</p> | ||
</div> | ||
</div> | ||
<div className='wallets-transactions-completed-row__transaction-details'> | ||
<p | ||
className={`wallets-transactions-completed-row__transaction-details__amount ${ | ||
transaction?.amount && transaction.amount < 0 | ||
? 'wallets-transactions-completed-row__transaction-details__amount--negative' | ||
: '' | ||
}`} | ||
> | ||
{formattedAmount} | ||
</p> | ||
<p className='wallets-transactions-completed-row__transaction-details__balance'> | ||
Balance: {transaction.balance_after} | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default WalletTransactionsCompletedRow; |
Oops, something went wrong.