@@ -2,21 +2,24 @@ import "./payment-methods-select.scss";
22
33import * as React from "react" ;
44import { 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 " ;
77import { BlockchainTicker } from "src/types/index" ;
88import 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" ;
119import useSharedMerchantId from "src/hooks/use-merchant-id" ;
1210import useSharedMerchant from "src/hooks/use-merchant" ;
11+ import PaymentMethodsItem from "src/components/payment-method-item/payment-method-item" ;
1312
14- const b = bevis ( "payment-methods-select" ) ;
13+ interface AvailableBlockchainsType {
14+ name : string ;
15+ }
1516
1617const PaymentMethodsSelect : React . FC = ( ) => {
1718 const { merchant, getMerchant} = useSharedMerchant ( ) ;
1819 const { merchantId} = useSharedMerchantId ( ) ;
1920 const [ supportedMethodsReqState , updateSupportedMethods ] = useAsyncFn ( merchantProvider . updateSupportedMethods ) ;
21+ const [ availableBlockchains , setAvailableBlockchains ] = React . useState < AvailableBlockchainsType [ ] > ( [ ] ) ;
22+ const [ isAvailableBlockchainsLoading , setIsAvailableBlockchainsLoading ] = React . useState < boolean > ( false ) ;
2023
2124 const onChange = ( ticker : BlockchainTicker ) => {
2225 if ( ! merchantId || ! merchant ?. supportedPaymentMethods ) {
@@ -32,6 +35,47 @@ const PaymentMethodsSelect: React.FC = () => {
3235 updateSupportedMethods ( merchantId , { supportedPaymentMethods} ) ;
3336 } ;
3437
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+
3579 const updateMerchant = async ( ) => {
3680 if ( ! merchantId ) {
3781 return ;
@@ -48,30 +92,33 @@ const PaymentMethodsSelect: React.FC = () => {
4892 updateMerchant ( ) ;
4993 } , [ merchantId ] ) ;
5094
95+ React . useEffect ( ( ) => {
96+ setIsAvailableBlockchainsLoading ( true ) ;
97+ setAvailableBlockchains ( getBlockchainsList ( ) ) ;
98+ setIsAvailableBlockchainsLoading ( false ) ;
99+ } , [ merchant ?. supportedPaymentMethods ] ) ;
100+
51101 return (
52102 < >
53103 < Row align = "middle" justify = "space-between" >
54104 < Typography . Title level = { 3 } > Accepted Currencies</ Typography . Title >
55105 </ 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+ />
75122 </ >
76123 ) ;
77124} ;
0 commit comments