diff --git a/api/typeDefs/wallet.js b/api/typeDefs/wallet.js index 65bc9761..20b327a6 100644 --- a/api/typeDefs/wallet.js +++ b/api/typeDefs/wallet.js @@ -1,8 +1,6 @@ import { gql } from 'graphql-tag' -const sharedSend = 'walletId: ID, templateName: ID, enabled: Boolean!' - -const sharedRecv = `${sharedSend}, networkTests: Boolean` +const shared = 'walletId: ID, templateName: ID, enabled: Boolean!' const typeDefs = gql` extend type Query { @@ -24,78 +22,76 @@ const typeDefs = gql` sendToLnAddr(addr: String!, amount: Int!, maxFee: Int!, comment: String, identifier: Boolean, name: String, email: String): Withdrawl! cancelInvoice(hash: String!, hmac: String, userCancel: Boolean): Invoice! dropBolt11(hash: String!): Boolean - removeWallet(id: ID!): Boolean - deleteWalletLogs(protocolId: Int, debug: Boolean): Boolean - setWalletPriorities(priorities: [WalletPriorityUpdate!]!): Boolean buyCredits(credits: Int!): BuyCreditsPaidAction! + # upserts upsertWalletSendLNbits( - ${sharedSend}, + ${shared}, url: String!, apiKey: VaultEntryInput! ): WalletSendLNbits! upsertWalletRecvLNbits( - ${sharedRecv}, + ${shared}, url: String!, apiKey: String! ): WalletRecvLNbits! upsertWalletSendPhoenixd( - ${sharedSend}, + ${shared}, url: String!, apiKey: VaultEntryInput! ): WalletSendPhoenixd! upsertWalletRecvPhoenixd( - ${sharedRecv}, + ${shared}, url: String!, apiKey: String! ): WalletRecvPhoenixd! upsertWalletSendBlink( - ${sharedSend}, + ${shared}, currency: VaultEntryInput!, apiKey: VaultEntryInput! ): WalletSendBlink! upsertWalletRecvBlink( - ${sharedRecv}, + ${shared}, currency: String!, apiKey: String! ): WalletRecvBlink! upsertWalletRecvLightningAddress( - ${sharedRecv}, + ${shared}, address: String! ): WalletRecvLightningAddress! upsertWalletSendNWC( - ${sharedSend}, + ${shared}, url: VaultEntryInput! ): WalletSendNWC! upsertWalletRecvNWC( - ${sharedRecv}, + ${shared}, url: String! ): WalletRecvNWC! upsertWalletRecvCLNRest( - ${sharedRecv}, + ${shared}, socket: String!, rune: String!, cert: String ): WalletRecvCLNRest! upsertWalletRecvLNDGRPC( - ${sharedRecv}, + ${shared}, socket: String!, macaroon: String!, cert: String ): WalletRecvLNDGRPC! upsertWalletSendLNC( - ${sharedSend}, + ${shared}, pairingPhrase: VaultEntryInput!, localKey: VaultEntryInput!, remoteKey: VaultEntryInput!, @@ -103,16 +99,62 @@ const typeDefs = gql` ): WalletSendLNC! upsertWalletSendWebLN( - ${sharedSend} + ${shared} ): WalletSendWebLN! + # tests + testWalletRecvNWC( + url: String! + ): Boolean! + + testWalletRecvLightningAddress( + address: String! + ): Boolean! + + testWalletRecvCLNRest( + socket: String!, + rune: String!, + cert: String + ): Boolean! + + testWalletRecvLNDGRPC( + socket: String!, + macaroon: String!, + cert: String + ): Boolean! + + testWalletRecvPhoenixd( + url: String! + apiKey: String! + ): Boolean! + + testWalletRecvLNbits( + url: String! + apiKey: String! + ): Boolean! + + testWalletRecvBlink( + currency: String! + apiKey: String! + ): Boolean! + + # delete + removeWallet(id: ID!): Boolean removeWalletProtocol(id: ID!): Boolean + + # crypto updateWalletEncryption(keyHash: String!, wallets: [WalletEncryptionUpdate!]!): Boolean updateKeyHash(keyHash: String!): Boolean resetWallets(newKeyHash: String!): Boolean disablePassphraseExport: Boolean + + # settings setWalletSettings(settings: WalletSettingsInput!): Boolean + setWalletPriorities(priorities: [WalletPriorityUpdate!]!): Boolean + + # logs addWalletLog(protocolId: Int, level: String!, message: String!, timestamp: Date!, invoiceId: Int): Boolean + deleteWalletLogs(protocolId: Int, debug: Boolean): Boolean } type BuyCreditsResult { diff --git a/wallets/README.md b/wallets/README.md index 755fb53a..e517d598 100644 --- a/wallets/README.md +++ b/wallets/README.md @@ -291,7 +291,7 @@ index 26c292d9..3ac88ae1 100644 - add GraphQL type - add GraphQL type to `WalletProtocolConfig` union - add GraphQL type to `WalletProtocolFields` fragment via spread operator (...) -- add GraphQL mutation to upsert protocol +- add GraphQL mutation to upsert and test protocol - resolve GraphQL type in `mapWalletResolveTypes` function
@@ -303,10 +303,10 @@ index 3c1fffd1..af3858a5 100644 --- a/api/typeDefs/wallet.js +++ b/api/typeDefs/wallet.js @@ -38,6 +38,7 @@ const typeDefs = gql` - upsertWalletRecvLNDGRPC(walletId: ID, templateId: ID, enabled: Boolean!, networkTests: Boolean, socket: String!, macaroon: String!, cert: String): WalletRecvLNDGRPC! + upsertWalletRecvLNDGRPC(walletId: ID, templateId: ID, enabled: Boolean!, socket: String!, macaroon: String!, cert: String): WalletRecvLNDGRPC! upsertWalletSendLNC(walletId: ID, templateId: ID, enabled: Boolean!, pairingPhrase: VaultEntryInput!, localKey: VaultEntryInput!, remoteKey: VaultEntryInput!, serverHost: VaultEntryInput!): WalletSendLNC! upsertWalletSendWebLN(walletId: ID, templateId: ID, enabled: Boolean!): WalletSendWebLN! -+ upsertWalletRecvBolt12(walletId: ID, templateId: ID, enabled: Boolean!, networkTests: Boolean, offer: String!): WalletRecvBolt12! ++ upsertWalletRecvBolt12(walletId: ID, templateId: ID, enabled: Boolean!, offer: String!): WalletRecvBolt12! removeWalletProtocol(id: ID!): Boolean updateWalletEncryption(keyHash: String!, wallets: [WalletEncryptionUpdate!]!): Boolean updateKeyHash(keyHash: String!): Boolean @@ -340,8 +340,8 @@ index d1a65ff4..138d1a62 100644 ` + +export const UPSERT_WALLET_RECEIVE_BOLT12 = gql` -+ mutation upsertWalletRecvBolt12($walletId: ID, $templateId: ID, $enabled: Boolean!, $networkTests: Boolean, $offer: String!) { -+ upsertWalletRecvBolt12(walletId: $walletId, templateId: $templateId, enabled: $enabled, networkTests: $networkTests, offer: $offer) { ++ mutation upsertWalletRecvBolt12($walletId: ID, $templateId: ID, $enabled: Boolean!, $offer: String!) { ++ upsertWalletRecvBolt12(walletId: $walletId, templateId: $templateId, enabled: $enabled, offer: $offer) { + id + } + } diff --git a/wallets/client/fragments/protocol.js b/wallets/client/fragments/protocol.js index 14a55ab8..c39a327f 100644 --- a/wallets/client/fragments/protocol.js +++ b/wallets/client/fragments/protocol.js @@ -1,29 +1,26 @@ import { gql } from '@apollo/client' -const sharedSend = { +const shared = { variables: '$walletId: ID, $templateName: ID, $enabled: Boolean!', arguments: 'walletId: $walletId, templateName: $templateName, enabled: $enabled' } -const sharedRecv = { - variables: `${sharedSend.variables}, $networkTests: Boolean`, - arguments: `${sharedSend.arguments}, networkTests: $networkTests` -} - export const REMOVE_WALLET_PROTOCOL = gql` mutation removeWalletProtocol($id: ID!) { removeWalletProtocol(id: $id) } ` +// upserts + export const UPSERT_WALLET_SEND_LNBITS = gql` mutation upsertWalletSendLNbits( - ${sharedSend.variables}, + ${shared.variables}, $url: String!, $apiKey: VaultEntryInput! ) { upsertWalletSendLNbits( - ${sharedSend.arguments} + ${shared.arguments} url: $url, apiKey: $apiKey ) { @@ -34,12 +31,12 @@ export const UPSERT_WALLET_SEND_LNBITS = gql` export const UPSERT_WALLET_RECEIVE_LNBITS = gql` mutation upsertWalletRecvLNbits( - ${sharedRecv.variables}, + ${shared.variables}, $url: String!, $apiKey: String! ) { upsertWalletRecvLNbits( - ${sharedRecv.arguments}, + ${shared.arguments}, url: $url, apiKey: $apiKey ) { @@ -50,12 +47,12 @@ export const UPSERT_WALLET_RECEIVE_LNBITS = gql` export const UPSERT_WALLET_SEND_PHOENIXD = gql` mutation upsertWalletSendPhoenixd( - ${sharedSend.variables}, + ${shared.variables}, $url: String!, $apiKey: VaultEntryInput! ) { upsertWalletSendPhoenixd( - ${sharedSend.arguments}, + ${shared.arguments}, url: $url, apiKey: $apiKey ) { @@ -66,12 +63,12 @@ export const UPSERT_WALLET_SEND_PHOENIXD = gql` export const UPSERT_WALLET_RECEIVE_PHOENIXD = gql` mutation upsertWalletRecvPhoenixd( - ${sharedRecv.variables}, + ${shared.variables}, $url: String!, $apiKey: String! ) { upsertWalletRecvPhoenixd( - ${sharedRecv.arguments}, + ${shared.arguments}, url: $url, apiKey: $apiKey ) { @@ -82,12 +79,12 @@ export const UPSERT_WALLET_RECEIVE_PHOENIXD = gql` export const UPSERT_WALLET_SEND_BLINK = gql` mutation upsertWalletSendBlink( - ${sharedSend.variables}, + ${shared.variables}, $currency: VaultEntryInput!, $apiKey: VaultEntryInput! ) { upsertWalletSendBlink( - ${sharedSend.arguments}, + ${shared.arguments}, currency: $currency, apiKey: $apiKey ) { @@ -98,12 +95,12 @@ export const UPSERT_WALLET_SEND_BLINK = gql` export const UPSERT_WALLET_RECEIVE_BLINK = gql` mutation upsertWalletRecvBlink( - ${sharedRecv.variables}, + ${shared.variables}, $currency: String!, $apiKey: String! ) { upsertWalletRecvBlink( - ${sharedRecv.arguments}, + ${shared.arguments}, currency: $currency, apiKey: $apiKey ) { @@ -114,11 +111,11 @@ export const UPSERT_WALLET_RECEIVE_BLINK = gql` export const UPSERT_WALLET_RECEIVE_LIGHTNING_ADDRESS = gql` mutation upsertWalletRecvLightningAddress( - ${sharedRecv.variables}, + ${shared.variables}, $address: String! ) { upsertWalletRecvLightningAddress( - ${sharedRecv.arguments}, + ${shared.arguments}, address: $address ) { id @@ -128,11 +125,11 @@ export const UPSERT_WALLET_RECEIVE_LIGHTNING_ADDRESS = gql` export const UPSERT_WALLET_SEND_NWC = gql` mutation upsertWalletSendNWC( - ${sharedSend.variables}, + ${shared.variables}, $url: VaultEntryInput! ) { upsertWalletSendNWC( - ${sharedSend.arguments}, + ${shared.arguments}, url: $url ) { id @@ -142,11 +139,11 @@ export const UPSERT_WALLET_SEND_NWC = gql` export const UPSERT_WALLET_RECEIVE_NWC = gql` mutation upsertWalletRecvNWC( - ${sharedRecv.variables}, + ${shared.variables}, $url: String! ) { upsertWalletRecvNWC( - ${sharedRecv.arguments}, + ${shared.arguments}, url: $url ) { id @@ -156,13 +153,13 @@ export const UPSERT_WALLET_RECEIVE_NWC = gql` export const UPSERT_WALLET_RECEIVE_CLN_REST = gql` mutation upsertWalletRecvCLNRest( - ${sharedRecv.variables}, + ${shared.variables}, $socket: String!, $rune: String!, $cert: String ) { upsertWalletRecvCLNRest( - ${sharedRecv.arguments}, + ${shared.arguments}, socket: $socket, rune: $rune, cert: $cert @@ -174,13 +171,13 @@ export const UPSERT_WALLET_RECEIVE_CLN_REST = gql` export const UPSERT_WALLET_RECEIVE_LND_GRPC = gql` mutation upsertWalletRecvLNDGRPC( - ${sharedRecv.variables}, + ${shared.variables}, $socket: String!, $macaroon: String!, $cert: String ) { upsertWalletRecvLNDGRPC( - ${sharedRecv.arguments}, + ${shared.arguments}, socket: $socket, macaroon: $macaroon, cert: $cert @@ -192,14 +189,14 @@ export const UPSERT_WALLET_RECEIVE_LND_GRPC = gql` export const UPSERT_WALLET_SEND_LNC = gql` mutation upsertWalletSendLNC( - ${sharedSend.variables}, + ${shared.variables}, $pairingPhrase: VaultEntryInput!, $localKey: VaultEntryInput!, $remoteKey: VaultEntryInput!, $serverHost: VaultEntryInput! ) { upsertWalletSendLNC( - ${sharedSend.arguments}, + ${shared.arguments}, pairingPhrase: $pairingPhrase, localKey: $localKey, remoteKey: $remoteKey, @@ -212,12 +209,56 @@ export const UPSERT_WALLET_SEND_LNC = gql` export const UPSERT_WALLET_SEND_WEBLN = gql` mutation upsertWalletSendWebLN( - ${sharedSend.variables} + ${shared.variables} ) { upsertWalletSendWebLN( - ${sharedSend.arguments} + ${shared.arguments} ) { id } } ` + +// tests + +export const TEST_WALLET_RECEIVE_NWC = gql` + mutation testWalletRecvNWC($url: String!) { + testWalletRecvNWC(url: $url) + } +` + +export const TEST_WALLET_RECEIVE_LIGHTNING_ADDRESS = gql` + mutation testWalletRecvLightningAddress($address: String!) { + testWalletRecvLightningAddress(address: $address) + } +` + +export const TEST_WALLET_RECEIVE_CLN_REST = gql` + mutation testWalletRecvCLNRest($socket: String!, $rune: String!, $cert: String) { + testWalletRecvCLNRest(socket: $socket, rune: $rune, cert: $cert) + } +` + +export const TEST_WALLET_RECEIVE_LND_GRPC = gql` + mutation testWalletRecvLNDGRPC($socket: String!, $macaroon: String!, $cert: String) { + testWalletRecvLNDGRPC(socket: $socket, macaroon: $macaroon, cert: $cert) + } +` + +export const TEST_WALLET_RECEIVE_PHOENIXD = gql` + mutation testWalletRecvPhoenixd($url: String!, $apiKey: String!) { + testWalletRecvPhoenixd(url: $url, apiKey: $apiKey) + } +` + +export const TEST_WALLET_RECEIVE_LNBITS = gql` + mutation testWalletRecvLNbits($url: String!, $apiKey: String!) { + testWalletRecvLNbits(url: $url, apiKey: $apiKey) + } +` + +export const TEST_WALLET_RECEIVE_BLINK = gql` + mutation testWalletRecvBlink($currency: String!, $apiKey: String!) { + testWalletRecvBlink(currency: $currency, apiKey: $apiKey) + } +` diff --git a/wallets/client/hooks/query.js b/wallets/client/hooks/query.js index e1a9bb7e..71cf7a0e 100644 --- a/wallets/client/hooks/query.js +++ b/wallets/client/hooks/query.js @@ -19,9 +19,16 @@ import { RESET_WALLETS, DISABLE_PASSPHRASE_EXPORT, SET_WALLET_PRIORITIES, - UPDATE_KEY_HASH + UPDATE_KEY_HASH, + TEST_WALLET_RECEIVE_LNBITS, + TEST_WALLET_RECEIVE_PHOENIXD, + TEST_WALLET_RECEIVE_BLINK, + TEST_WALLET_RECEIVE_LIGHTNING_ADDRESS, + TEST_WALLET_RECEIVE_NWC, + TEST_WALLET_RECEIVE_CLN_REST, + TEST_WALLET_RECEIVE_LND_GRPC } from '@/wallets/client/fragments' -import { useApolloClient, useMutation, useQuery } from '@apollo/client' +import { gql, useApolloClient, useMutation, useQuery } from '@apollo/client' import { useDecryption, useEncryption, useSetKey, useWalletLogger, useWalletsUpdatedAt, WalletStatus } from '@/wallets/client/hooks' import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { @@ -144,10 +151,11 @@ export function useWalletQuery ({ id, name }) { } export function useWalletProtocolUpsert (wallet, protocol) { - const mutation = getWalletProtocolMutation(protocol) + const mutation = getWalletProtocolUpsertMutation(protocol) const [mutate] = useMutation(mutation) const { encryptConfig } = useEncryptConfig(protocol) const testSendPayment = useTestSendPayment(protocol) + const testCreateInvoice = useTestCreateInvoice(protocol) const logger = useWalletLogger(protocol) return useCallback(async (values) => { @@ -158,11 +166,14 @@ export function useWalletProtocolUpsert (wallet, protocol) { } // skip network tests if we're disabling the wallet - const networkTests = values.enabled - if (networkTests) { + if (values.enabled) { try { - const additionalValues = await testSendPayment(values) - values = { ...values, ...additionalValues } + if (protocol.send) { + const additionalValues = await testSendPayment(values) + values = { ...values, ...additionalValues } + } else { + await testCreateInvoice(values) + } } catch (err) { logger.error(err.message) throw err @@ -172,9 +183,6 @@ export function useWalletProtocolUpsert (wallet, protocol) { const encrypted = await encryptConfig(values) const variables = encrypted - if (!protocol.send) { - variables.networkTests = networkTests - } if (isWallet(wallet)) { variables.walletId = wallet.id } else { @@ -194,7 +202,7 @@ export function useWalletProtocolUpsert (wallet, protocol) { requestPersistentStorage() return updatedWallet - }, [wallet, protocol, logger, testSendPayment, encryptConfig, mutate]) + }, [wallet, protocol, logger, testSendPayment, testCreateInvoice, encryptConfig, mutate]) } export function useLightningAddressUpsert () { @@ -286,7 +294,12 @@ export function useSetWalletPriorities () { }, [mutate, toaster]) } -function getWalletProtocolMutation (protocol) { +// we only have test mutations for receive protocols and useMutation throws if we pass null to it, +// so we use this placeholder mutation in such cases to respect the rules of hooks. +// (the mutation would throw if called but we make sure to never call it.) +const NOOP_MUTATION = gql`mutation noop { noop }` + +function getWalletProtocolUpsertMutation (protocol) { switch (protocol.name) { case 'LNBITS': return protocol.send ? UPSERT_WALLET_SEND_LNBITS : UPSERT_WALLET_RECEIVE_LNBITS @@ -295,26 +308,47 @@ function getWalletProtocolMutation (protocol) { case 'BLINK': return protocol.send ? UPSERT_WALLET_SEND_BLINK : UPSERT_WALLET_RECEIVE_BLINK case 'LN_ADDR': - return protocol.send ? null : UPSERT_WALLET_RECEIVE_LIGHTNING_ADDRESS + return protocol.send ? NOOP_MUTATION : UPSERT_WALLET_RECEIVE_LIGHTNING_ADDRESS case 'NWC': return protocol.send ? UPSERT_WALLET_SEND_NWC : UPSERT_WALLET_RECEIVE_NWC case 'CLN_REST': - return protocol.send ? null : UPSERT_WALLET_RECEIVE_CLN_REST + return protocol.send ? NOOP_MUTATION : UPSERT_WALLET_RECEIVE_CLN_REST case 'LND_GRPC': - return protocol.send ? null : UPSERT_WALLET_RECEIVE_LND_GRPC + return protocol.send ? NOOP_MUTATION : UPSERT_WALLET_RECEIVE_LND_GRPC case 'LNC': - return protocol.send ? UPSERT_WALLET_SEND_LNC : null + return protocol.send ? UPSERT_WALLET_SEND_LNC : NOOP_MUTATION case 'WEBLN': - return protocol.send ? UPSERT_WALLET_SEND_WEBLN : null + return protocol.send ? UPSERT_WALLET_SEND_WEBLN : NOOP_MUTATION default: - return null + return NOOP_MUTATION + } +} + +function getWalletProtocolTestMutation (protocol) { + if (protocol.send) return NOOP_MUTATION + + switch (protocol.name) { + case 'LNBITS': + return TEST_WALLET_RECEIVE_LNBITS + case 'PHOENIXD': + return TEST_WALLET_RECEIVE_PHOENIXD + case 'BLINK': + return TEST_WALLET_RECEIVE_BLINK + case 'LN_ADDR': + return TEST_WALLET_RECEIVE_LIGHTNING_ADDRESS + case 'NWC': + return TEST_WALLET_RECEIVE_NWC + case 'CLN_REST': + return TEST_WALLET_RECEIVE_CLN_REST + case 'LND_GRPC': + return TEST_WALLET_RECEIVE_LND_GRPC + default: + return NOOP_MUTATION } } function useTestSendPayment (protocol) { return useCallback(async (values) => { - if (!protocol.send) return - return await protocolTestSendPayment( protocol, values, @@ -323,6 +357,15 @@ function useTestSendPayment (protocol) { }, [protocol]) } +function useTestCreateInvoice (protocol) { + const mutation = getWalletProtocolTestMutation(protocol) + const [testCreateInvoice] = useMutation(mutation) + + return useCallback(async (values) => { + return await testCreateInvoice({ variables: values }) + }, [testCreateInvoice]) +} + function useWalletDecryption () { const { decryptConfig, ready } = useDecryptConfig() @@ -452,7 +495,7 @@ export function useWalletMigrationMutation () { } await client.mutate({ - mutation: getWalletProtocolMutation(protocol), + mutation: getWalletProtocolUpsertMutation(protocol), variables: { ...(walletId ? { walletId } : { templateName }), enabled, diff --git a/wallets/lib/util.js b/wallets/lib/util.js index fbe12c44..9c606adb 100644 --- a/wallets/lib/util.js +++ b/wallets/lib/util.js @@ -76,6 +76,11 @@ export function protocolMutationName ({ name, send }) { return `upsert${relationName.charAt(0).toUpperCase() + relationName.slice(1)}` } +export function protocolTestMutationName ({ name, send }) { + const relationName = protocolRelationName({ name, send }) + return `test${relationName.charAt(0).toUpperCase() + relationName.slice(1)}` +} + export function protocolFields ({ name, send }) { return protocol({ name, send })?.fields || [] } diff --git a/wallets/server/resolvers/protocol.js b/wallets/server/resolvers/protocol.js index 7207d471..f53e8d4f 100644 --- a/wallets/server/resolvers/protocol.js +++ b/wallets/server/resolvers/protocol.js @@ -1,7 +1,7 @@ import { GqlAuthenticationError, GqlInputError } from '@/lib/error' import { validateSchema } from '@/lib/validate' import protocols from '@/wallets/lib/protocols' -import { protocolRelationName, isEncryptedField, protocolMutationName, protocolServerSchema } from '@/wallets/lib/util' +import { protocolRelationName, isEncryptedField, protocolMutationName, protocolServerSchema, protocolTestMutationName } from '@/wallets/lib/util' import { mapWalletResolveTypes } from '@/wallets/server/resolvers/util' import { protocolTestCreateInvoice } from '@/wallets/server/protocols' import { timeoutSignal, withTimeout } from '@/lib/time' @@ -43,12 +43,23 @@ export const resolvers = { }, Mutation: { ...Object.fromEntries( - protocols.map(protocol => { + protocols.reduce((acc, protocol) => { return [ - protocolMutationName(protocol), - upsertWalletProtocol(protocol) + ...acc, + [ + protocolMutationName(protocol), + upsertWalletProtocol(protocol) + ], + ...(protocol.send + ? [] + : [ + [ + protocolTestMutationName(protocol), + testWalletProtocol(protocol) + ] + ]) ] - }) + }, []) ), addWalletLog, removeWalletProtocol, @@ -56,12 +67,43 @@ export const resolvers = { } } +function testWalletProtocol (protocol) { + return async (parent, args, { me, models, tx }) => { + if (!me) { + throw new GqlAuthenticationError() + } + + if (protocol.send) { + throw new GqlInputError('can only test receive protocols') + } + + let invoice + try { + invoice = await withTimeout( + protocolTestCreateInvoice( + protocol, + args, + { signal: timeoutSignal(WALLET_CREATE_INVOICE_TIMEOUT_MS) } + ), + WALLET_CREATE_INVOICE_TIMEOUT_MS + ) + } catch (e) { + throw new GqlInputError('failed to create invoice: ' + e.message) + } + + if (!invoice || !invoice.startsWith('lnbc')) { + throw new GqlInputError('wallet returned invalid invoice') + } + + return true + } +} + export function upsertWalletProtocol (protocol) { return async (parent, { walletId, templateName, enabled, - networkTests = true, ignoreKeyHash = false, ...args }, { me, models, tx }) => { @@ -84,22 +126,6 @@ export function upsertWalletProtocol (protocol) { throw new GqlInputError(e.message) } - if (!protocol.send && networkTests) { - let invoice - try { - invoice = await withTimeout( - protocolTestCreateInvoice(protocol, args, { signal: timeoutSignal(WALLET_CREATE_INVOICE_TIMEOUT_MS) }), - WALLET_CREATE_INVOICE_TIMEOUT_MS - ) - } catch (e) { - throw new GqlInputError('failed to create test invoice: ' + e.message) - } - - if (!invoice || !invoice.startsWith('lnbc')) { - throw new GqlInputError('wallet returned invalid invoice') - } - } - const relation = protocolRelationName(protocol) function dataFragment (args, type) { diff --git a/wallets/server/resolvers/wallet.js b/wallets/server/resolvers/wallet.js index 8053d1d7..e07368d5 100644 --- a/wallets/server/resolvers/wallet.js +++ b/wallets/server/resolvers/wallet.js @@ -134,7 +134,7 @@ async function updateWalletEncryption (parent, { keyHash, wallets }, { me, model for (const { id: walletId, protocols } of wallets) { for (const { name, send, config } of protocols) { const mutation = upsertWalletProtocol({ name, send }) - await mutation(parent, { walletId, networkTests: false, ignoreKeyHash: true, ...config }, { me, models: tx, tx }) + await mutation(parent, { walletId, ignoreKeyHash: true, ...config }, { me, models: tx, tx }) } }