Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit 253b60c

Browse files
authored
Merge pull request #26 from oxygenpay/develop
merge: develop
2 parents 7f7d695 + 715a27c commit 253b60c

File tree

9 files changed

+132
-85
lines changed

9 files changed

+132
-85
lines changed
Lines changed: 1 addition & 8 deletions
Loading
Lines changed: 1 addition & 10 deletions
Loading
Lines changed: 1 addition & 10 deletions
Loading
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import * as React from "react";
2+
import bevis from "src/utils/bevis";
3+
import {Space, Tag} from "antd";
4+
import SpinWithMask from "src/components/spin-with-mask/spin-with-mask";
5+
import {BlockchainTicker, PaymentMethod} from "src/types/index";
6+
import Icon from "src/components/icon/icon";
7+
8+
const b = bevis("payment-methods-select");
9+
10+
interface Props {
11+
title: string;
12+
items: PaymentMethod[];
13+
onChange: (ticker: BlockchainTicker) => void;
14+
isLoading: boolean;
15+
}
16+
17+
const PaymentMethodsItem: React.FC<Props> = (props: Props) => {
18+
return (
19+
<Space size={[0, 8]} wrap className={b()}>
20+
{props.items.map((item) => (
21+
<Tag
22+
key={item.name}
23+
icon={<Icon name={item.name.toLowerCase()} dir="crypto" className={b("icon")} />}
24+
color={item.enabled ? "#1777ff" : "#bebebe"}
25+
className={b("option")}
26+
>
27+
<span className={b("option-text")}>{item.name}</span>
28+
<div
29+
className={b("overlay")}
30+
onClick={(e) => {
31+
e.stopPropagation();
32+
props.onChange(item.ticker);
33+
}}
34+
/>
35+
<SpinWithMask isLoading={props.isLoading} />
36+
</Tag>
37+
))}
38+
</Space>
39+
);
40+
};
41+
42+
export default PaymentMethodsItem;

ui-dashboard/src/components/payment-methods-select/payment-methods-select.scss

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,31 @@
88
&__option {
99
display: flex;
1010
align-items: center;
11+
justify-content: center;
1112
position: relative;
12-
height: 58px;
13-
width: 250px;
14-
padding: 8px 16px;
13+
height: 30px;
14+
width: 66px;
15+
padding: 2px 4px;
1516
border: 1px solid #d9d9d9;
1617
border-radius: 6px;
1718
margin-right: 16px;
1819
margin-bottom: 16px;
20+
21+
&-text {
22+
font-size: 10px;
23+
}
1924
}
2025

2126
&__icon {
22-
margin-left: auto;
23-
height: 24px;
27+
width: 16px;
28+
height: 16px;
29+
margin-right: 5px;
2430
}
2531

2632
&__overlay {
2733
position: absolute;
34+
left: 0;
35+
top: 0;;
2836
z-index: 2;
2937
cursor: pointer;
3038
width: 100%;

ui-dashboard/src/components/payment-methods-select/payment-methods-select.tsx

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@ import "./payment-methods-select.scss";
22

33
import * as React from "react";
44
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";
77
import {BlockchainTicker} from "src/types/index";
88
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";
119
import useSharedMerchantId from "src/hooks/use-merchant-id";
1210
import 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

1617
const 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

Comments
 (0)