More zap undo fixes (#872)
* Don't throw error if invoice attached * Only show progress bar for undo toasts * Update zap undo info in settings * Skip zap undo toast flow for external payments
This commit is contained in:
parent
cd4f243106
commit
817234a7fa
@ -83,7 +83,11 @@ export default function ItemAct ({ onClose, itemId, down, children }) {
|
|||||||
let canceled
|
let canceled
|
||||||
const sats = values.amount
|
const sats = values.amount
|
||||||
const insufficientFunds = me?.privates?.sats < sats
|
const insufficientFunds = me?.privates?.sats < sats
|
||||||
if (insufficientFunds) throw new Error('insufficient funds')
|
const invoiceAttached = values.hash && values.hmac
|
||||||
|
if (insufficientFunds && !invoiceAttached) throw new Error('insufficient funds')
|
||||||
|
// payments from external wallets already have their own flow
|
||||||
|
// and we don't want to show undo toasts for them
|
||||||
|
const skipToastFlow = invoiceAttached
|
||||||
// update function for optimistic UX
|
// update function for optimistic UX
|
||||||
const update = () => {
|
const update = () => {
|
||||||
const fragment = {
|
const fragment = {
|
||||||
@ -108,10 +112,14 @@ export default function ItemAct ({ onClose, itemId, down, children }) {
|
|||||||
}
|
}
|
||||||
let undoUpdate
|
let undoUpdate
|
||||||
return {
|
return {
|
||||||
|
skipToastFlow,
|
||||||
flowId,
|
flowId,
|
||||||
type: 'zap',
|
type: 'zap',
|
||||||
pendingMessage: `${down ? 'down' : ''}zapped ${sats} sats`,
|
pendingMessage: `${down ? 'down' : ''}zapped ${sats} sats`,
|
||||||
onPending: async () => {
|
onPending: async () => {
|
||||||
|
if (skipToastFlow) {
|
||||||
|
return onSubmit(values, { flowId, ...args, update: null })
|
||||||
|
}
|
||||||
await strike()
|
await strike()
|
||||||
onClose()
|
onClose()
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -180,7 +180,7 @@ export const ToastProvider = ({ children }) => {
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</ToastBody>
|
</ToastBody>
|
||||||
{toast.delay > 0 && <div className={`${styles.progressBar} ${styles[toast.variant]}`} style={{ animationDelay }} />}
|
{toast.onUndo && toast.delay > 0 && <div className={`${styles.progressBar} ${styles[toast.variant]}`} style={{ animationDelay }} />}
|
||||||
</Toast>
|
</Toast>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
@ -205,10 +205,13 @@ export const withToastFlow = (toaster) => flowFn => {
|
|||||||
onUndo,
|
onUndo,
|
||||||
hideError,
|
hideError,
|
||||||
hideSuccess,
|
hideSuccess,
|
||||||
|
skipToastFlow,
|
||||||
...toastProps
|
...toastProps
|
||||||
} = flowFn(...args)
|
} = flowFn(...args)
|
||||||
let canceled
|
let canceled
|
||||||
|
|
||||||
|
if (skipToastFlow) return onPending()
|
||||||
|
|
||||||
// XXX HACK this ends the flow by using flow toast which immediately closes itself
|
// XXX HACK this ends the flow by using flow toast which immediately closes itself
|
||||||
const endFlow = () => toaster.warning('', { ...toastProps, delay: 0, autohide: true, flowId })
|
const endFlow = () => toaster.warning('', { ...toastProps, delay: 0, autohide: true, flowId })
|
||||||
|
|
||||||
|
@ -176,6 +176,12 @@ export default function Settings ({ ssrData }) {
|
|||||||
<ul className='fw-bold'>
|
<ul className='fw-bold'>
|
||||||
<li>An undo button is shown after every zap</li>
|
<li>An undo button is shown after every zap</li>
|
||||||
<li>The button is shown for 5 seconds</li>
|
<li>The button is shown for 5 seconds</li>
|
||||||
|
<li>
|
||||||
|
The button is only shown for zaps from the custodial wallet
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
Use a budget or manual approval with attached wallets
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</Info>
|
</Info>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user