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

receiver and sender fallback #1523

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 6 additions & 5 deletions api/paidAction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export default async function performPaidAction (actionType, args, { ...context
context.me = context.me ? await models.user.findUnique({ where: { id: context.me.id } }) : undefined
context.cost = await paidAction.getCost(args, context)
context.sybilFeePercent = await paidAction.getSybilFeePercent?.(args, context)
context.attempt = context.attempt ?? 0 // how many times the client thinks it has tried
context.forceInternal = context.forceInternal ?? false // use only internal payment methods
context.prioritizeInternal = context.prioritizeInternal ?? false // prefer internal payment methods
context.attempt ??= 0 // how many times the client thinks it has tried
context.forceInternal ??= false // use only internal payment methods
context.prioritizeInternal ??= false // prefer internal payment methods
context.description = context.me?.hideInvoiceDesc ? undefined : await paidAction.describe?.(args, context)
context.descriptionHash = await paidAction.describeHash?.(args, context)
ekzyis marked this conversation as resolved.
Show resolved Hide resolved
context.supportedPaymentMethods = paidAction.paymentMethods ?? await paidAction.getPaymentMethods?.(args, context) ?? []
Expand Down Expand Up @@ -108,7 +108,7 @@ export default async function performPaidAction (actionType, args, { ...context

if (paymentMethod === PAID_ACTION_PAYMENT_METHODS.P2P) {
try {
return await performP2PAction(actionType, args, context, paymentMethod)
return await performP2PAction(actionType, args, context)
} catch (e) {
// p2p can fail for various reasons, if it does, we should try another payment method
console.error('paid action failed with P2P payment method, try another one', e)
Expand Down Expand Up @@ -238,7 +238,7 @@ async function performP2PAction (actionType, args, { ...context }) {
description,
descriptionHash,
expiry: INVOICE_EXPIRE_SECS,
skipWallets: attempt
walletOffset: attempt
}, { models, me, lnd })

context.invoiceArgs = {
Expand Down Expand Up @@ -291,6 +291,7 @@ export async function retryPaidAction ({ invoiceId, forceInternal, attempt, prio
context.prioritizeInternal = prioritizeInternal

return await models.$transaction(async tx => {
context.tx = tx
const supportRetrying = paidAction.retry
if (supportRetrying) {
// update the old invoice to RETRYING, so that it's not confused with FAILED
Expand Down
2 changes: 1 addition & 1 deletion components/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const useWalletPayment = () => {
const defaultWallet = useWallet()

const waitForWalletPayment = useCallback(async ({ id, bolt11 }, waitFor, wallet) => {
wallet = wallet ?? defaultWallet
wallet ??= defaultWallet
if (!wallet) {
throw new NoAttachedWalletError()
}
Expand Down
6 changes: 2 additions & 4 deletions components/qr.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ export default function Qr ({ asIs, value, useWallet: automated, statusVariant,

useEffect(() => {
async function effect () {
const usableWallets = wallets.filter(w => !w.def.isAvailable || w.def.isAvailable())
.filter(w => w.config?.enabled && canSend(w))[0]
if (automated && usableWallets.length > 0) {
for (const wallet of usableWallets) {
if (automated && wallets.length > 0) {
for (const wallet of wallets) {
ekzyis marked this conversation as resolved.
Show resolved Hide resolved
try {
await wallet.sendPayment(value)
break
Expand Down
29 changes: 15 additions & 14 deletions wallets/server.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// import server side wallets
import * as lnd from '@wallets/lnd/server'
import * as cln from '@wallets/cln/server'
import * as lnAddr from '@wallets/lightning-address/server'
import * as lnbits from 'wallets/lnbits/server'
import * as nwc from '@wallets/nwc/server'
import * as phoenixd from '@wallets/phoenixd/server'
import * as blink from '@wallets/blink/server'
import * as lnd from '@/wallets/lnd/server'
import * as cln from '@/wallets/cln/server'
import * as lnAddr from '@/wallets/lightning-address/server'
import * as lnbits from '@/wallets/lnbits/server'
import * as nwc from '@/wallets/nwc/server'
import * as phoenixd from '@/wallets/phoenixd/server'
import * as blink from '@/wallets/blink/server'

// we import only the metadata of client side wallets
import * as lnc from '@wallets/lnc'
import * as webln from '@wallets/webln'
import * as lnc from '@/wallets/lnc'
import * as webln from '@/wallets/webln'

import { walletLogger } from '@/api/resolvers/wallet'
import walletDefs from '@wallets/server'
import walletDefs from '@/wallets/server'
import { parsePaymentRequest } from 'ln-service'
import { toNumber, toPositiveBigInt } from '@/lib/validate'
import { PAID_ACTION_TERMINAL_STATES } from '@/lib/constants'
Expand All @@ -25,7 +25,7 @@ export default [lnd, cln, lnAddr, lnbits, nwc, phoenixd, blink, lnc, webln]

const MAX_PENDING_INVOICES_PER_WALLET = 25

export async function createInvoice (userId, { msats, description, descriptionHash, expiry = 360, wrap = false, feePercent, skipWallets = 0 }, { models, me, lnd }) {
export async function createInvoice (userId, { msats, description, descriptionHash, expiry = 360, wrap = false, feePercent, walletOffset = 0 }, { models, me, lnd }) {
// get the wallets in order of priority
const wallets = await getInvoiceableWallets(userId, { models })

Expand All @@ -37,7 +37,8 @@ export async function createInvoice (userId, { msats, description, descriptionHa
innerMsats = msats * (100n - feePercent) / 100n
}

for (let i = toNumber(Math.min(skipWallets, wallets.length), 0, wallets.length); i < wallets.length; i++) {
const offset = toNumber(Math.min(walletOffset, wallets.length), 0, wallets.length)
for (let i = offset; i < wallets.length; i++) {
const { def, wallet } = wallets[i]

const config = wallet.wallet
Expand Down Expand Up @@ -108,7 +109,7 @@ export async function createInvoice (userId, { msats, description, descriptionHa
}

export async function createWrappedInvoice (userId,
{ msats, feePercent, description, descriptionHash, expiry = 360, skipWallets = 0 },
{ msats, feePercent, description, descriptionHash, expiry = 360, walletOffset = 0 },
{ models, me, lnd }) {
return await createInvoice(userId, {
// this is the amount the stacker will receive, the other (feePercent)% is our fee
Expand All @@ -118,7 +119,7 @@ export async function createWrappedInvoice (userId,
description,
descriptionHash,
expiry,
skipWallets
walletOffset
}, { models, me, lnd })
}

Expand Down
Loading