-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSendTransactionModal.tsx
119 lines (113 loc) · 5.66 KB
/
SendTransactionModal.tsx
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { FormEvent, useState } from 'react'
import { useAtom, useAtomValue } from 'jotai'
import ReactModal from 'react-modal'
import { modalAtom, selectedWalletAtom } from '../libs/atoms'
import { venlyConnect } from '../libs/venlyConnect'
import { useAlerts } from '../hooks/useAlerts'
import { copyAddress, formatAddress } from '../libs/utils'
import circlesSm from '../assets/circles-sm.svg'
export default function SendTransactionModal() {
const { showAlert } = useAlerts()
const [modal, setModal] = useAtom(modalAtom)
const selectedWallet = useAtomValue(selectedWalletAtom)
const [formFields, setFormFields] = useState({
to: '',
value: '',
})
function onAfterClose() {
setFormFields({
to: '',
value: '',
})
}
async function handleSubmit(event: FormEvent) {
event.preventDefault()
try {
const res = await venlyConnect.signer.executeTransfer({
walletId: selectedWallet!.id,
to: formFields.to,
value: Number(formFields.value),
secretType: selectedWallet!.secretType,
})
showAlert('Send transaction', res)
setModal(null)
}
catch (error) {
showAlert('Send transaction', error)
}
}
return (
<ReactModal
isOpen={modal == 'SendTransactionModal'}
parentSelector={() => document.querySelector('.app')!}
overlayClassName="modal-overlay"
className="modal"
onRequestClose={() => setModal(null)}
onAfterClose={onAfterClose}
>
<form onSubmit={e => handleSubmit(e)}>
<button type="button" className="btn btn--close" onClick={() => setModal(null)}>
<svg width="24" height="24" viewBox="0 0 24 24" fill="none">
<path d="M18 6L6 18M6 6L18 18" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
</svg>
</button>
<div className="modal-header">
<div className="modal-header__icon">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none">
<path d="M20 17H4M4 17L8 13M4 17L8 21M4 7H20M20 7L16 3M20 7L16 11" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
</svg>
<div className="modal-header__bg">
<img src={circlesSm} width={336} height={336}/>
</div>
</div>
<h2 className="modal-header__title">Send transaction</h2>
<p className="modal-header__subtitle">Allows you to transfer native tokens from one address to another.</p>
</div>
<div className="modal-form">
<div className="form-field">
<label className="form-field__label">Wallet</label>
<div className="form-field__container">
<div className="input-dropdown">
<div className="input-dropdown__input">
{selectedWallet &&
<>
<img src={`/chains/${selectedWallet.secretType.toLowerCase()}.svg`}
className="input-dropdown__img" alt={selectedWallet.secretType}
/>
<span className="input-dropdown__text">{selectedWallet.description}</span>
<span className="input-dropdown__subtext">{formatAddress(selectedWallet?.address)}</span>
</>
}
</div>
<div className="input-dropdown__btn" onClick={() => copyAddress(selectedWallet?.address)}>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none">
<path d="M5 15C4.06812 15 3.60218 15 3.23463 14.8478C2.74458 14.6448 2.35523 14.2554 2.15224 13.7654C2 13.3978 2 12.9319 2 12V5.2C2 4.0799 2 3.51984 2.21799 3.09202C2.40973 2.71569 2.71569 2.40973 3.09202 2.21799C3.51984 2 4.0799 2 5.2 2H12C12.9319 2 13.3978 2 13.7654 2.15224C14.2554 2.35523 14.6448 2.74458 14.8478 3.23463C15 3.60218 15 4.06812 15 5M12.2 22H18.8C19.9201 22 20.4802 22 20.908 21.782C21.2843 21.5903 21.5903 21.2843 21.782 20.908C22 20.4802 22 19.9201 22 18.8V12.2C22 11.0799 22 10.5198 21.782 10.092C21.5903 9.71569 21.2843 9.40973 20.908 9.21799C20.4802 9 19.9201 9 18.8 9H12.2C11.0799 9 10.5198 9 10.092 9.21799C9.71569 9.40973 9.40973 9.71569 9.21799 10.092C9 10.5198 9 11.0799 9 12.2V18.8C9 19.9201 9 20.4802 9.21799 20.908C9.40973 21.2843 9.71569 21.5903 10.092 21.782C10.5198 22 11.0799 22 12.2 22Z" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/>
</svg>
Copy
</div>
</div>
</div>
<span className="form-field__subtext">Balance: {selectedWallet?.balance?.balance} {selectedWallet?.balance?.symbol}</span>
</div>
<div className="form-field">
<label className="form-field__label">To</label>
<input type="text" className="form-field__input" placeholder="Public address (0x)"
value={formFields.to} onChange={e => setFormFields({...formFields, to: e.target.value})}
/>
</div>
<div className="form-field">
<label className="form-field__label">Amount ({selectedWallet?.balance?.symbol ?? 'ETH'})</label>
<input type="text" className="form-field__input"
placeholder="e.g. 0.001"
value={formFields.value} onChange={e => setFormFields({...formFields, value: e.target.value})}
/>
</div>
</div>
<div className="modal__buttons">
<button type="submit" className="btn btn--primary btn--large">Confirm</button>
<button type="button" className="btn btn--large" onClick={() => setModal(null)}>Cancel</button>
</div>
</form>
</ReactModal>
)
}