Commit a973be9f authored by zeroleak's avatar zeroleak
Browse files

fix tx0 preview

parent 652b49c0
......@@ -15,7 +15,7 @@ export default function GenericModal(props) {
</Modal.Body>
<Modal.Footer>
{modalUtils.isLoading() && <div className="modal-status">
<div className="spinner-border spinner-border-sm" role="status"/> {modalUtils.loading}
<div className="spinner-border spinner-border-sm" role="status"/> {modalUtils.getLoadingMessage()}
</div>}
{!modalUtils.isLoading() && modalUtils.isError() && <div className="modal-status">
<Alert variant='danger'>{modalUtils.error}</Alert>
......
......@@ -61,10 +61,10 @@ export default function Tx0Modal(props) {
// tx0 preview
useEffect(() => {
if (!isTx0Possible(tx0FeeTarget, mixFeeTarget, poolId, utxos)) {
// cannot preview yet
setTx0Preview(undefined)
} else {
// clear old tx0Preview
setTx0Preview(undefined)
if (isTx0Possible(tx0FeeTarget, mixFeeTarget, poolId, utxos)) {
// preview
modalUtils.load("Loading...", backendService.tx0.tx0Preview(utxos, tx0FeeTarget, mixFeeTarget, poolId).then(newTx0Preview => {
setTx0Preview(newTx0Preview)
......
export default class ModalUtils {
constructor(useState, useEffect) {
const [loading, setLoading] = useState(false)
const [loading, setLoading] = useState([])
this.loading = loading
this.setLoading = setLoading
......@@ -20,7 +20,11 @@ export default class ModalUtils {
}
isLoading() {
return this.loading
return this.loading.length > 0
}
getLoadingMessage() {
return this.loading[this.loading.length-1]
}
isError() {
......@@ -28,11 +32,15 @@ export default class ModalUtils {
}
load(loadingMessage, promise) {
this.loading = loadingMessage
this.error = undefined
const loading1 = this.loading
loading1.push(loadingMessage)
this.setLoading(loading1)
this.setError(undefined)
return promise.then(result => {
this.setLoading(false)
const loading2 = this.loading
loading2.pop()
this.setLoading(loading2)
if (this.error) {
this.setError(false)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment