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
|
||||
const sats = values.amount
|
||||
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
|
||||
const update = () => {
|
||||
const fragment = {
|
||||
|
@ -108,10 +112,14 @@ export default function ItemAct ({ onClose, itemId, down, children }) {
|
|||
}
|
||||
let undoUpdate
|
||||
return {
|
||||
skipToastFlow,
|
||||
flowId,
|
||||
type: 'zap',
|
||||
pendingMessage: `${down ? 'down' : ''}zapped ${sats} sats`,
|
||||
onPending: async () => {
|
||||
if (skipToastFlow) {
|
||||
return onSubmit(values, { flowId, ...args, update: null })
|
||||
}
|
||||
await strike()
|
||||
onClose()
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
|
@ -180,7 +180,7 @@ export const ToastProvider = ({ children }) => {
|
|||
</Button>
|
||||
</div>
|
||||
</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>
|
||||
)
|
||||
})}
|
||||
|
@ -205,10 +205,13 @@ export const withToastFlow = (toaster) => flowFn => {
|
|||
onUndo,
|
||||
hideError,
|
||||
hideSuccess,
|
||||
skipToastFlow,
|
||||
...toastProps
|
||||
} = flowFn(...args)
|
||||
let canceled
|
||||
|
||||
if (skipToastFlow) return onPending()
|
||||
|
||||
// XXX HACK this ends the flow by using flow toast which immediately closes itself
|
||||
const endFlow = () => toaster.warning('', { ...toastProps, delay: 0, autohide: true, flowId })
|
||||
|
||||
|
|
|
@ -176,6 +176,12 @@ export default function Settings ({ ssrData }) {
|
|||
<ul className='fw-bold'>
|
||||
<li>An undo button is shown after every zap</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>
|
||||
</Info>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue