Skip to content

Commit bb2b093

Browse files
committed
feat(wallet): retrieve and top-up multiple wallet on portal
1 parent ca89d75 commit bb2b093

File tree

14 files changed

+237
-142
lines changed

14 files changed

+237
-142
lines changed

src/components/customerPortal/common/hooks/useCustomerPortalNavigation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ const useCustomerPortalNavigation = () => {
2424
}),
2525
)
2626

27-
const viewWallet = () =>
27+
const viewWallet = (walletId: string) =>
2828
navigate(
2929
generatePath(CUSTOMER_PORTAL_WALLET_ROUTE, {
3030
token: token as string,
31+
walletId,
3132
}),
3233
)
3334

src/components/customerPortal/wallet/WalletPage.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { gql } from '@apollo/client'
22
import { InputAdornment } from '@mui/material'
33
import { useFormik } from 'formik'
4+
import { useParams } from 'react-router-dom'
45
import { number, object } from 'yup'
56

67
import useCustomerPortalNavigation from '~/components/customerPortal/common/hooks/useCustomerPortalNavigation'
@@ -13,11 +14,20 @@ import { AmountInputField } from '~/components/form'
1314
import { intlFormatNumber } from '~/core/formats/intlFormatNumber'
1415
import {
1516
CurrencyEnum,
16-
useGetPortalWalletsQuery,
17+
useCustomerPortalWalletQuery,
1718
useTopUpPortalWalletMutation,
1819
} from '~/generated/graphql'
1920

2021
gql`
22+
query customerPortalWallet($id: ID!) {
23+
customerPortalWallet(id: $id) {
24+
id
25+
currency
26+
name
27+
rateAmount
28+
}
29+
}
30+
2131
mutation TopUpPortalWallet($input: CreateCustomerPortalWalletTransactionInput!) {
2232
createCustomerPortalWalletTransaction(input: $input) {
2333
collection {
@@ -28,6 +38,7 @@ gql`
2838
`
2939

3040
const WalletPage = () => {
41+
const { walletId = '' } = useParams()
3142
const { goHome } = useCustomerPortalNavigation()
3243
const { translate, documentLocale } = useCustomerPortalTranslate()
3344

@@ -36,7 +47,11 @@ const WalletPage = () => {
3647
loading: customerWalletLoading,
3748
error: customerWalletError,
3849
refetch: customerWalletRefetch,
39-
} = useGetPortalWalletsQuery()
50+
} = useCustomerPortalWalletQuery({
51+
variables: {
52+
id: walletId,
53+
},
54+
})
4055

4156
const [topUpPortalWallet, { loading: loadingTopUpPortalWallet, error: errorTopUpPortalWallet }] =
4257
useTopUpPortalWalletMutation({
@@ -49,7 +64,7 @@ const WalletPage = () => {
4964
},
5065
})
5166

52-
const wallet = customerWalletData?.customerPortalWallets?.collection?.[0]
67+
const wallet = customerWalletData?.customerPortalWallet
5368

5469
const formikProps = useFormik({
5570
initialValues: {
@@ -75,8 +90,7 @@ const WalletPage = () => {
7590
const submitButtonDisabled =
7691
!formikProps?.values?.amount || loadingTopUpPortalWallet || formikProps?.values?.amount <= 0
7792

78-
const isLoading = customerWalletLoading
79-
const isError = !isLoading && customerWalletError
93+
const isError = !customerWalletLoading && customerWalletError
8094

8195
if (isError) {
8296
return (
@@ -92,9 +106,9 @@ const WalletPage = () => {
92106
<div>
93107
<PageTitle title={translate('text_1728498418253nyv3qmz9k5k')} goHome={goHome} />
94108

95-
{isLoading && <LoaderWalletPage />}
109+
{customerWalletLoading && <LoaderWalletPage />}
96110

97-
{!isLoading && (
111+
{!customerWalletLoading && (
98112
<div>
99113
<AmountInputField
100114
name="amount"

0 commit comments

Comments
 (0)