-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathblock.js
54 lines (44 loc) · 1.22 KB
/
block.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { __ } from '@wordpress/i18n';
import { decodeEntities } from '@wordpress/html-entities';
import { getSetting } from '@woocommerce/settings';
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
const settings = getSetting( 'blockonomics_data', {} );
const defaultLabel = __( 'Bitcoin', 'blockonomics-bitcoin-payments' );
const label = decodeEntities( settings.title ) || defaultLabel;
const getIcons = () => {
return Object.entries( settings?.icons ?? {} ).map(
( [ id, { src, alt } ] ) => {
return {
id,
src,
alt,
};
}
);
};
const Label = ( props ) => {
const { PaymentMethodLabel, PaymentMethodIcons } = props.components;
return (
<>
<PaymentMethodLabel text={ label } />
<PaymentMethodIcons icons={getIcons()} />
</>
);
};
const Content = () => {
return decodeEntities( settings.description || '' );
};
const canMakePayment = () => {
return true;
};
const blockonomicsPaymentMethod = {
name: 'blockonomics',
label: <Label />,
content: <Content />,
edit: <Content />,
canMakePayment,
ariaLabel: label,
icons: getIcons(),
placeOrderButtonLabel: __( 'Pay with Bitcoin', 'blockonomics-bitcoin-payments' )
}
registerPaymentMethod( blockonomicsPaymentMethod );