-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransfer.js
More file actions
85 lines (79 loc) · 2.49 KB
/
Copy pathTransfer.js
File metadata and controls
85 lines (79 loc) · 2.49 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React, { useEffect, useState } from 'react';
import { Form, Input, Grid, Label, Icon } from 'semantic-ui-react';
import { TxButton } from './substrate-lib/components';
import { encodeApn } from './helpers.js';
export default function Main (props) {
const [status, setStatus] = useState(null);
const [formState, setFormState] = useState({ addressFrom: null, addressTo: null, amount: 0 });
const { accountPair } = props;
const onChange = (_, data) => {
setFormState(prev => ({ ...prev, [data.state]: data.value }));
setAddressFromEncoded(encodeApn(addressFrom, true));
setAddressToEncoded(encodeApn(addressTo, true));
};
const [addressFromEncoded, setAddressFromEncoded] = useState('');
const [addressToEncoded, setAddressToEncoded] = useState('');
const { addressFrom, addressTo, amount } = formState;
return (
<Grid.Column width={8}>
<h1>Water Transfer</h1>
<Form>
<Form.Field>
<Input
fluid
label='From'
type='text'
placeholder='address'
state='addressFrom'
onChange={onChange}
/>
</Form.Field>
<Form.Field>
<Input
fluid
label='To'
type='text'
placeholder='address'
state='addressTo'
onChange={onChange}
/>
</Form.Field>
<Form.Field>
<Input
fluid
label='Amount'
type='number'
state='amount'
onChange={onChange}
/>
</Form.Field>
<Form.Field style={{ textAlign: 'center' }}>
<TxButton
accountPair={accountPair}
label='Submit'
type='SIGNED-TX'
setStatus={setStatus}
attrs={{
palletRpc: 'allocator',
callable: 'tradeTokens',
inputParams: [
'0',
{type: 'Source', value: addressFromEncoded},
{type: 'Source', value: addressToEncoded},
amount
],
interxType: 'EXTRINSIC',
paramFields: [
{name: 'assetID', type: 'AssetId'},
{name: 'fromapn', type: 'Source'},
{name: 'toapn', type: 'Source'},
{name: 'amt', type: 'Balance1'}
]
}}
/>
</Form.Field>
<div style={{ overflowWrap: 'break-word' }}>{status}</div>
</Form>
</Grid.Column>
);
}