@@ -2,21 +2,24 @@ import "./payment-methods-select.scss";
2
2
3
3
import * as React from "react" ;
4
4
import { useAsyncFn , useMount } from "react-use" ;
5
- import bevis from "src/utils/bevis " ;
6
- import { Checkbox , Row , Typography } from "antd" ;
5
+ import { Row , Typography , Table , Result } from "antd " ;
6
+ import { ColumnsType } from "antd/es/table " ;
7
7
import { BlockchainTicker } from "src/types/index" ;
8
8
import merchantProvider from "src/providers/merchant-provider" ;
9
- import Icon from "src/components/icon/icon" ;
10
- import SpinWithMask from "src/components/spin-with-mask/spin-with-mask" ;
11
9
import useSharedMerchantId from "src/hooks/use-merchant-id" ;
12
10
import useSharedMerchant from "src/hooks/use-merchant" ;
11
+ import PaymentMethodsItem from "src/components/payment-method-item/payment-method-item" ;
13
12
14
- const b = bevis ( "payment-methods-select" ) ;
13
+ interface AvailableBlockchainsType {
14
+ name : string ;
15
+ }
15
16
16
17
const PaymentMethodsSelect : React . FC = ( ) => {
17
18
const { merchant, getMerchant} = useSharedMerchant ( ) ;
18
19
const { merchantId} = useSharedMerchantId ( ) ;
19
20
const [ supportedMethodsReqState , updateSupportedMethods ] = useAsyncFn ( merchantProvider . updateSupportedMethods ) ;
21
+ const [ availableBlockchains , setAvailableBlockchains ] = React . useState < AvailableBlockchainsType [ ] > ( [ ] ) ;
22
+ const [ isAvailableBlockchainsLoading , setIsAvailableBlockchainsLoading ] = React . useState < boolean > ( false ) ;
20
23
21
24
const onChange = ( ticker : BlockchainTicker ) => {
22
25
if ( ! merchantId || ! merchant ?. supportedPaymentMethods ) {
@@ -32,6 +35,47 @@ const PaymentMethodsSelect: React.FC = () => {
32
35
updateSupportedMethods ( merchantId , { supportedPaymentMethods} ) ;
33
36
} ;
34
37
38
+ const paymentMethodsColumns : ColumnsType < AvailableBlockchainsType > = [
39
+ {
40
+ title : "Network" ,
41
+ dataIndex : "network" ,
42
+ key : "network" ,
43
+ width : "min-content" ,
44
+ render : ( _ , record ) => < span style = { { whiteSpace : "nowrap" } } > { record . name } </ span >
45
+ } ,
46
+ {
47
+ title : "Currencies" ,
48
+ dataIndex : "currencies" ,
49
+ key : "currencies" ,
50
+ render : ( _ , record ) => (
51
+ < div >
52
+ < div key = { record . name } >
53
+ < PaymentMethodsItem
54
+ title = { record . name }
55
+ items = {
56
+ merchant ?. supportedPaymentMethods . filter (
57
+ ( paymentItem ) => paymentItem . blockchainName === record . name
58
+ ) ?? [ ]
59
+ }
60
+ onChange = { onChange }
61
+ isLoading = { supportedMethodsReqState . loading }
62
+ />
63
+ </ div >
64
+ </ div >
65
+ )
66
+ }
67
+ ] ;
68
+
69
+ const getBlockchainsList = ( ) => {
70
+ if ( ! merchant ) {
71
+ return [ ] ;
72
+ }
73
+
74
+ return [ ...new Set ( merchant . supportedPaymentMethods . map ( ( item ) => item . blockchainName ) ) ] . map ( ( item ) => ( {
75
+ name : item
76
+ } ) ) ;
77
+ } ;
78
+
35
79
const updateMerchant = async ( ) => {
36
80
if ( ! merchantId ) {
37
81
return ;
@@ -48,30 +92,33 @@ const PaymentMethodsSelect: React.FC = () => {
48
92
updateMerchant ( ) ;
49
93
} , [ merchantId ] ) ;
50
94
95
+ React . useEffect ( ( ) => {
96
+ setIsAvailableBlockchainsLoading ( true ) ;
97
+ setAvailableBlockchains ( getBlockchainsList ( ) ) ;
98
+ setIsAvailableBlockchainsLoading ( false ) ;
99
+ } , [ merchant ?. supportedPaymentMethods ] ) ;
100
+
51
101
return (
52
102
< >
53
103
< Row align = "middle" justify = "space-between" >
54
104
< Typography . Title level = { 3 } > Accepted Currencies</ Typography . Title >
55
105
</ Row >
56
- < div className = { b ( ) } >
57
- { merchant ?. supportedPaymentMethods . map ( ( item ) => (
58
- < div className = { b ( "option" ) } key = { item . ticker } >
59
- < Checkbox value = { item . ticker } style = { { lineHeight : "32px" } } checked = { item . enabled } >
60
- { item . displayName }
61
- </ Checkbox >
62
- < Icon name = { item . name . toLowerCase ( ) } dir = "crypto" className = { b ( "icon" ) } />
63
- { /* it's needed to prevent onClick on checkbox so as not to fire handler twice */ }
64
- < div
65
- className = { b ( "overlay" ) }
66
- onClick = { ( e ) => {
67
- e . stopPropagation ( ) ;
68
- onChange ( item . ticker ) ;
69
- } }
70
- />
71
- </ div >
72
- ) ) }
73
- < SpinWithMask isLoading = { supportedMethodsReqState . loading } />
74
- </ div >
106
+ < Table
107
+ columns = { paymentMethodsColumns }
108
+ dataSource = { availableBlockchains }
109
+ rowKey = { ( record ) => record . name }
110
+ loading = { isAvailableBlockchainsLoading }
111
+ pagination = { false }
112
+ size = "middle"
113
+ locale = { {
114
+ emptyText : (
115
+ < Result
116
+ icon = { null }
117
+ title = "Accepted currencies will appear there after you add new type of supported currency"
118
+ > </ Result >
119
+ )
120
+ } }
121
+ />
75
122
</ >
76
123
) ;
77
124
} ;
0 commit comments