Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small ui improvements and bugfixes #1

Merged
merged 5 commits into from
Jan 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/components/Payment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export default function Payment({ currentWallet }) {
const [alert, setAlert] = useState(null)
const [isSending, setIsSending] = useState(false)
const [isCoinjoin, setIsCoinjoin] = useState(false)
const [account, setAccount] = useState(location.state?.account || 0)
const [account, setAccount] = useState(parseInt(location.state?.account, 10) || 0)

const sendPayment = async (account, destination, amount_sats) => {
const { name, token } = currentWallet
const opts = {
method: 'POST',
headers: { 'Authorization': `Bearer ${token}` },
body: JSON.stringify({
mixdepth: account,
mixdepth: String(account),
destination,
amount_sats
})
Expand Down Expand Up @@ -53,7 +53,7 @@ export default function Payment({ currentWallet }) {
method: 'POST',
headers: { 'Authorization': `Bearer ${token}` },
body: JSON.stringify({
mixdepth: account,
mixdepth: String(account),
destination,
amount_sats,
counterparties
Expand Down Expand Up @@ -91,7 +91,7 @@ export default function Payment({ currentWallet }) {
setValidated(true)

if (isValid) {
const { account, amount, counterparties, destination } = serialize(form)
const { amount, counterparties, destination } = serialize(form)
const success = isCoinjoin
? await startCoinjoin(account, destination, amount, counterparties)
: await sendPayment(account, destination, amount)
Expand All @@ -115,13 +115,14 @@ export default function Payment({ currentWallet }) {
</rb.Form.Group>
<rb.Form.Group className="mb-3" controlId="account">
<rb.Form.Label>Account</rb.Form.Label>
<rb.Form.Control name="account" type="number" value={account} min={ACCOUNTS[0]} max={ACCOUNTS[4]} onChange={e => setAccount(parseInt(e.target.value, 10))} style={{ width: '15ch' }} required />
<rb.Form.Control.Feedback type="invalid">Please provide an account between {ACCOUNTS[0]} and {ACCOUNTS[4]}.</rb.Form.Control.Feedback>
<rb.Form.Select defaultValue={account} onChange={e => setAccount(parseInt(e.target.value, 10))} style={{ maxWidth: '21ch' }} required>
{ACCOUNTS.map(val => <option key={val} value={val}>Account {val}</option>)}
</rb.Form.Select>
</rb.Form.Group>
<rb.Form.Group className="mb-3" controlId="amount">
<rb.Form.Label>Amount in Sats</rb.Form.Label>
<rb.Form.Control name="amount" type="number" min={0} defaultValue={0} required style={{ maxWidth: '15ch' }}/>
<rb.Form.Control.Feedback type="invalid">Please provide a receiving address.</rb.Form.Control.Feedback>
<rb.Form.Control name="amount" type="number" min={1} defaultValue={0} required style={{ maxWidth: '21ch' }}/>
<rb.Form.Control.Feedback type="invalid">Please provide a valid amount.</rb.Form.Control.Feedback>
</rb.Form.Group>
<rb.Form.Group className="mb-3" controlId="isCoinjoin">
<rb.Form.Check type="switch" label="As coinjoin" value={true} onChange={(e) => setIsCoinjoin(e.target.checked)} />
Expand Down
14 changes: 9 additions & 5 deletions src/components/Receive.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Receive = ({ currentWallet }) => {
const [isLoading, setIsLoading] = useState(false)
const [address, setAddress] = useState('')
const [amount, setAmount] = useState(0)
const [account, setAccount] = useState(location.state?.account || 0)
const [account, setAccount] = useState(parseInt(location.state?.account, 10) || 0)
const [addressCount, setAddressCount] = useState(0)

useEffect(() => {
Expand All @@ -37,7 +37,10 @@ const Receive = ({ currentWallet }) => {
.finally(() => setIsLoading(false))

}
if (ACCOUNTS.includes(account)) fetchAddress(account)

if (ACCOUNTS.includes(account)) {
fetchAddress(account)
}

return () => abortCtrl.abort()
}, [account, currentWallet, addressCount])
Expand Down Expand Up @@ -69,13 +72,14 @@ const Receive = ({ currentWallet }) => {
)}
<rb.Form.Group className="mb-3" controlId="account">
<rb.Form.Label>Account</rb.Form.Label>
<rb.Form.Control name="account" type="number" value={account} min={ACCOUNTS[0]} max={ACCOUNTS[4]} onChange={e => setAccount(parseInt(e.target.value, 10))} style={{ width: '10ch' }} required />
<rb.Form.Control.Feedback type="invalid">Please provide an account between {ACCOUNTS[0]} and {ACCOUNTS[4]}.</rb.Form.Control.Feedback>
<rb.Form.Select defaultValue={account} onChange={e => setAccount(parseInt(e.target.value, 10))} style={{ maxWidth: '21ch' }} required>
{ACCOUNTS.map(val => <option key={val} value={val}>Account {val}</option>)}
</rb.Form.Select>
</rb.Form.Group>
<rb.Form.Group className="mb-3" controlId="amountSats">
<rb.Form.Label>Amount in Sats</rb.Form.Label>
<rb.Form.Control name="amount" type="number" value={amount} min={0} onChange={e => setAmount(e.target.value)} style={{ width: '21ch' }} />
<rb.Form.Control.Feedback type="invalid">Please provide a receiving address.</rb.Form.Control.Feedback>
<rb.Form.Control.Feedback type="invalid">Please provide a valid amount.</rb.Form.Control.Feedback>
</rb.Form.Group>
<rb.Form.Group className="mb-3" controlId="address">
<rb.Form.Label>Address</rb.Form.Label>
Expand Down