diff --git a/src/components/App.jsx b/src/components/App.jsx
index fd18265e..7244b5ba 100644
--- a/src/components/App.jsx
+++ b/src/components/App.jsx
@@ -227,55 +227,55 @@ export default function App() {
- {currentWallet
- ? <>
- Wallet
- Payment
- Receive
- Maker
- >
- : null}
- {connection === true
- ? Create Wallet
- : null}
+ {currentWallet &&
+ <>
+ Wallet
+ Payment
+ Receive
+ Maker
+ >}
+ {connection === true &&
+ Create Wallet}
About
- {walletLoadStatus} ({activeWallet || 'None'} active) }
+ {walletLoadStatus} ({activeWallet || 'None'} active)
- {connection === true
- ? ` · YG ${makerStarted ? 'on' : 'off'}${coinjoinInProcess ? ', Coinjoining' : ''}`
- : null}
+ {connection === true &&
+ ` · YG ${makerStarted ? 'on' : 'off'}${coinjoinInProcess ? ', Coinjoining' : ''}`}
- {connection === false
- ? No connection to backend server.
- : null }
+ {connection === false &&
+ No connection to backend server.}
(
)} />
- (
-
- )} />
- (
-
- )} />
- (
-
- )} />
- (
-
- )} />
- (
-
- )} />
+ {currentWallet &&
+ <>
+ (
+
+ )} />
+ (
+
+ )} />
+ (
+
+ )} />
+ (
+
+ )} />
+ (
+
+ )} />
+ >
+ }
(
)} />
diff --git a/src/components/CreateWallet.jsx b/src/components/CreateWallet.jsx
index b5d9ff12..174502eb 100644
--- a/src/components/CreateWallet.jsx
+++ b/src/components/CreateWallet.jsx
@@ -80,9 +80,7 @@ export default function CreateWallet({ currentWallet, activeWallet }) {
return canCreate
?
Create Wallet
- {alert
- ? {alert.message}
- : null}
+ {alert && {alert.message}}
Wallet Name
diff --git a/src/components/CurrentWallet.jsx b/src/components/CurrentWallet.jsx
index 3e888f91..0f7c73ca 100644
--- a/src/components/CurrentWallet.jsx
+++ b/src/components/CurrentWallet.jsx
@@ -1,13 +1,15 @@
import React from 'react'
import { useState, useEffect } from 'react'
-import { Button } from './Button'
-import DisplayMixdepth from './DisplayMixdepth'
+import * as rb from 'react-bootstrap'
+import DisplayMixdepths from './DisplayMixdepths'
import DisplayUTXOs from './DisplayUTXOs'
-const CurrentWallet = ({ currentWallet, activeWallet, onSend, listUTXOs }) => {
- const [wallet_info, setWalletInfo] = useState([])
- const [UTXOHistory, setUTXOHistory] = useState({})
+export default function CurrentWallet ({ currentWallet, activeWallet, onSend, listUTXOs }) {
+ const [wallet_info, setWalletInfo] = useState(null)
+ const [UTXOHistory, setUTXOHistory] = useState(null)
const [showUTXO, setShowUTXO] = useState(false)
+ const [alert, setAlert] = useState(null)
+ const [isLoading, setIsLoading] = useState(false)
const listWalletInfo = async () => {
const { name, token } = currentWallet
@@ -16,26 +18,35 @@ const CurrentWallet = ({ currentWallet, activeWallet, onSend, listUTXOs }) => {
return alert(`Please unlock ${name} first`)
}
+ setAlert(null)
+ setIsLoading(true)
try {
const res = await fetch(`/api/v1/wallet/${name}/display`, {
headers: {
'Authorization': `Bearer ${token}`
}
})
- const { walletinfo } = await res.json()
- const balance = walletinfo.total_balance
- const mix_depths = walletinfo.accounts
- const wallet_info = { balance }
- wallet_info[mix_depths[0].account] = mix_depths[0].account_balance
- wallet_info[mix_depths[1].account] = mix_depths[1].account_balance
- wallet_info[mix_depths[2].account] = mix_depths[2].account_balance
- wallet_info[mix_depths[3].account] = mix_depths[3].account_balance
- wallet_info[mix_depths[4].account] = mix_depths[4].account_balance
- return [walletinfo]
+ if (res.ok) {
+ const { walletinfo } = await res.json()
+ const balance = walletinfo.total_balance
+ const mix_depths = walletinfo.accounts
+ const wallet_info = { balance }
+ wallet_info[mix_depths[0].account] = mix_depths[0].account_balance
+ wallet_info[mix_depths[1].account] = mix_depths[1].account_balance
+ wallet_info[mix_depths[2].account] = mix_depths[2].account_balance
+ wallet_info[mix_depths[3].account] = mix_depths[3].account_balance
+ wallet_info[mix_depths[4].account] = mix_depths[4].account_balance
+
+ return [walletinfo]
+ } else {
+ const { message } = await res.json()
+ setAlert({ variant: 'danger', message })
+ }
} catch (e) {
- console.error(e)
- alert('Error while loading.')
+ setAlert({ variant: 'danger', message: e.message })
+ } finally {
+ setIsLoading(false)
}
}
@@ -65,14 +76,12 @@ const CurrentWallet = ({ currentWallet, activeWallet, onSend, listUTXOs }) => {
}
const getWalletInfo = async () => {
const wallet_info = await listWalletInfo()
- console.log(wallet_info)
setWalletInfo(wallet_info)
}
const getUTXOs = async () => {
const utxos = await listUTXOs()
setUTXOHistory(utxos)
- console.log(utxos)
}
getWalletInfo()
@@ -82,20 +91,17 @@ const CurrentWallet = ({ currentWallet, activeWallet, onSend, listUTXOs }) => {
return (
{activeWallet}
- {wallet_info?.map((walletInfo, index) => {
- return
- })}
+ {alert &&
{alert.message}}
+ {isLoading &&
+ <>
+
+ Loading
+ >}
+ {wallet_info?.map((walletInfo) =>
)}
-
+ {UTXOHistory &&
{ setShowUTXO(!showUTXO) }}>{showUTXO ? 'Hide UTXOs' : 'Show UTXOs'}}
- { showUTXO
- ? Object.entries(UTXOHistory).map(([key, val]) =>
-
- )
- : null
- }
+ {UTXOHistory && showUTXO &&
}
)
}
-
-export default CurrentWallet
diff --git a/src/components/DisplayMixdepth.css b/src/components/DisplayMixdepth.css
deleted file mode 100644
index 3194f572..00000000
--- a/src/components/DisplayMixdepth.css
+++ /dev/null
@@ -1,18 +0,0 @@
-.head {
- font-size: small;
-}
-
-.address_label {
- text-align: right;
- padding-right: 7%;
- color: rgb(10, 192, 10);
-}
-
-.xpub {
- text-align: left;
- padding-left: 20px;
-}
-
-.branch_body{
- text-align: left;
-}
diff --git a/src/components/DisplayMixdepth.jsx b/src/components/DisplayMixdepth.jsx
deleted file mode 100644
index 9bde83f4..00000000
--- a/src/components/DisplayMixdepth.jsx
+++ /dev/null
@@ -1,99 +0,0 @@
-import React from 'react'
-import { Link } from 'react-router-dom'
-import * as rb from 'react-bootstrap'
-import './DisplayMixdepth.css'
-
-const DisplayMixdepth = ({ walletInfo }) => {
- const accounts = []
-
- for (const account_info of walletInfo.accounts) {
- accounts.push(account_info)
- }
-
- return (
-
- Total Balance: {walletInfo.total_balance} BTC
-
-
Maker Service
-
- {accounts.map((account, index) => (
-
-
-
-
-
-
-
-
- Account {accounts[index].account}
-
-
- Balance: {accounts[index].account_balance} BTC
-
-
- Send {' '}
-
-
- Receive
-
-
-
-
-
-
-
-
- External Addresses Balance: {accounts[index].branches[0].balance} BTC
-
- Extended Pubkey : {accounts[index].branches[0].branch.split("\t").pop()}
-
-
- {accounts[index].branches[0].entries.map((user, i) => (
-
-
-
-
- {accounts[index].branches[0].entries[i].labels}
-
- {accounts[index].branches[0].entries[i].address} {' '}
-
-
- amount: {accounts[index].branches[0].entries[i].amount}
-
-
-
-
-
- ))}
-
-
-
- Internal Addresses Balance: {accounts[index].branches[1].balance} BTC
-
- {accounts[index].branches[1].entries.map((user, j) => (
-
-
-
- {accounts[index].branches[0].entries[j].address} {' '} {accounts[index].branches[0].entries[j].labels}
-
-
- amount: {accounts[index].branches[0].entries[j].amount}
-
-
-
-
-
- ))}
-
-
-
-
-
-
-
- ))}
-
- )
-}
-
-export default DisplayMixdepth
diff --git a/src/components/DisplayMixdepths.jsx b/src/components/DisplayMixdepths.jsx
new file mode 100644
index 00000000..1d5aa8f2
--- /dev/null
+++ b/src/components/DisplayMixdepths.jsx
@@ -0,0 +1,94 @@
+import React from 'react'
+import { Link } from 'react-router-dom'
+import * as rb from 'react-bootstrap'
+
+export default function DisplayMixdepths({ walletInfo }) {
+ const accounts = []
+
+ for (const account_info of walletInfo.accounts) {
+ accounts.push(account_info)
+ }
+
+ return (
+
+ Total Balance: {walletInfo.total_balance} BTC
+
+
Maker Service
+
+
+ {accounts.map((account, index) => (
+
+
+
+
+
+
+ Account {accounts[index].account}
+
+
+ Balance: {accounts[index].account_balance} BTC
+
+
+ Send {' '}
+
+
+ Receive
+
+
+
+
+
+
+
+
+ External Addresses Balance: {accounts[index].branches[0].balance} BTC
+
+ Extended Pubkey : {accounts[index].branches[0].branch.split("\t").pop()}
+
+
+ {accounts[index].branches[0].entries.map((user, i) => (
+
+
+
+
+ {accounts[index].branches[0].entries[i].labels}
+
+ {accounts[index].branches[0].entries[i].address} {' '}
+
+
+ amount: {accounts[index].branches[0].entries[i].amount}
+
+
+
+
+
+ ))}
+
+
+
+ Internal Addresses Balance: {accounts[index].branches[1].balance} BTC
+
+ {accounts[index].branches[1].entries.map((user, j) => (
+
+
+
+ {accounts[index].branches[0].entries[j].address} {' '} {accounts[index].branches[0].entries[j].labels}
+
+
+ amount: {accounts[index].branches[0].entries[j].amount}
+
+
+
+
+
+ ))}
+
+
+
+
+
+ ))}
+
+
+ )
+}
diff --git a/src/components/DisplayUTXOs.jsx b/src/components/DisplayUTXOs.jsx
index edbff301..e6ec68c2 100644
--- a/src/components/DisplayUTXOs.jsx
+++ b/src/components/DisplayUTXOs.jsx
@@ -1,19 +1,42 @@
import React from 'react'
+import * as rb from 'react-bootstrap'
-const DisplayUTXOs = ({ utxoID, utxo }) => (
-
-
-
-
-
Address: {utxo.address}
-
-
Value(Sats): {utxo.value}
-
-
Confirmations: {utxo.confirmations}
-
-
Mixdepth: {utxo.mixdepth}
-
-
+const byMixdepth = utxos => {
+ const ret = utxos.reduce((res, utxo) => {
+ const { mixdepth } = utxo
+ res[mixdepth] = res[mixdepth] || []
+ res[mixdepth].push(utxo)
+ return res
+ }, {})
+ console.log(ret)
+ return ret
+}
+
+
+const DisplayUTXOs = ({ utxos }) => (
+
+ {Object.entries(byMixdepth(utxos)).map(([mixdepth, utxos]) => (
+
+
+ Mixdepth {mixdepth}
+
+
+
+
+
+ ))}
+
)
export default DisplayUTXOs
diff --git a/src/components/Wallet.jsx b/src/components/Wallet.jsx
index 4d99cb69..a72a9842 100644
--- a/src/components/Wallet.jsx
+++ b/src/components/Wallet.jsx
@@ -133,21 +133,20 @@ export default function Wallet({ name, currentWallet, activeWallet, setAlert })
Please remove the lock file on the server.
)
- : (noneActive
- ?
-
-
-
- {isUnlocking
- ? <>
-
- Unlocking
- >
- : 'Unlock'}
-
- Please set the wallet's password.
-
- : null)
+ : (noneActive &&
+
+
+
+
+ {isUnlocking
+ ? <>
+
+ Unlocking
+ >
+ : 'Unlock'}
+
+ Please set the wallet's password.
+ )
}
diff --git a/src/components/Wallets.jsx b/src/components/Wallets.jsx
index 71d37094..dde7e6d3 100644
--- a/src/components/Wallets.jsx
+++ b/src/components/Wallets.jsx
@@ -14,9 +14,7 @@ export default function Wallets({ currentWallet, activeWallet, walletList, onDis
return (
<>
Wallets
- {alert
- ?
- : null}
+ {alert && }
{walletList.map(wallet =>
)}
>