From b777fdcddc1a2f90164334c409fb5a2f01d561e5 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Tue, 16 Jul 2024 22:08:41 +0200 Subject: [PATCH] Fix wallet.server usage * I removed wallet.server in a previous commit * the client couldn't determine which wallet was stored on the server since all server specific fields were set in server.js * walletType and walletField are now set in index.js * walletType is now used to determine if a wallet is stored on the server * also included some formatting changes --- api/resolvers/wallet.js | 15 +++------------ components/wallet-logger.js | 6 +++--- pages/settings/wallets/[wallet].js | 4 ++-- wallets/cln/index.js | 4 ++++ wallets/cln/server.js | 4 ---- wallets/index.js | 10 ++++------ wallets/lightning-address/index.js | 4 ++++ wallets/lightning-address/server.js | 4 ---- wallets/lnd/index.js | 4 ++++ wallets/lnd/server.js | 4 ---- wallets/server.js | 3 --- 11 files changed, 24 insertions(+), 38 deletions(-) diff --git a/api/resolvers/wallet.js b/api/resolvers/wallet.js index 2a468acc..c4343ab4 100644 --- a/api/resolvers/wallet.js +++ b/api/resolvers/wallet.js @@ -22,11 +22,8 @@ function injectResolvers (resolvers) { // FIXME: this throws // TypeError: import_server.default is not iterable const w of walletDefs) { - const { - schema, - walletType, walletField, testConnect - // app and worker import file differently - } = w.default || w + // app and worker import file differently + const { schema, walletType, walletField, testConnect } = w.default || w const resolverName = generateResolverName(walletField) console.log(resolverName) resolvers.Mutation[resolverName] = async (parent, { settings, ...data }, { me, models }) => { @@ -34,13 +31,7 @@ function injectResolvers (resolvers) { schema, wallet: { field: walletField, type: walletType }, testConnect: (data) => - testConnect( - data, - { - me, - models - } - ) + testConnect(data, { me, models }) }, { settings, data }, { me, models }) } } diff --git a/components/wallet-logger.js b/components/wallet-logger.js index 361bb319..a68fe2e9 100644 --- a/components/wallet-logger.js +++ b/components/wallet-logger.js @@ -204,8 +204,8 @@ export const WalletLoggerProvider = ({ children }) => { }, [saveLog]) const deleteLogs = useCallback(async (wallet) => { - if (!wallet || wallet.server) { - await deleteServerWalletLogs({ variables: { wallet: wallet?.server?.walletType } }) + if (!wallet || wallet.walletType) { + await deleteServerWalletLogs({ variables: { wallet: wallet?.walletType } }) } if (!wallet || wallet.sendPayment) { const tx = idb.current.transaction(idbStoreName, 'readwrite') @@ -244,7 +244,7 @@ export function useWalletLogger (wallet) { } // don't store logs for receiving wallets on client since logs are stored on server - if (wallet.server) return + if (wallet.walletType) return // TODO: // also send this to us if diagnostics was enabled, diff --git a/pages/settings/wallets/[wallet].js b/pages/settings/wallets/[wallet].js index 4fbbfb38..9eabd3b9 100644 --- a/pages/settings/wallets/[wallet].js +++ b/pages/settings/wallets/[wallet].js @@ -37,7 +37,7 @@ export default function WalletSettings () {

{wallet.card.title}

{wallet.card.subtitle}
- {!wallet.server && } + {!wallet.walletType && }
- {wallet.server + {wallet.walletType ? : ( { @@ -245,7 +243,7 @@ export function getWalletByName (name) { } export function getWalletByType (type) { - return walletDefs.find(def => def.server?.walletType === type) + return walletDefs.find(def => def.walletType === type) } export function getEnabledWallet (me) { diff --git a/wallets/lightning-address/index.js b/wallets/lightning-address/index.js index 496a248f..8df1fa91 100644 --- a/wallets/lightning-address/index.js +++ b/wallets/lightning-address/index.js @@ -19,3 +19,7 @@ export const card = { } export const schema = lnAddrAutowithdrawSchema + +export const walletType = 'LIGHTNING_ADDRESS' + +export const walletField = 'walletLightningAddress' diff --git a/wallets/lightning-address/server.js b/wallets/lightning-address/server.js index 22b184ad..420f93a5 100644 --- a/wallets/lightning-address/server.js +++ b/wallets/lightning-address/server.js @@ -3,10 +3,6 @@ import { lnAddrOptions } from '@/lib/lnurl' export * from 'wallets/lightning-address' -export const walletType = 'LIGHTNING_ADDRESS' - -export const walletField = 'walletLightningAddress' - export const testConnect = async ( { address }, { me, models, addWalletLog } diff --git a/wallets/lnd/index.js b/wallets/lnd/index.js index 2ecf32ee..9d1dda4a 100644 --- a/wallets/lnd/index.js +++ b/wallets/lnd/index.js @@ -41,3 +41,7 @@ export const card = { } export const schema = LNDAutowithdrawSchema + +export const walletType = 'LND' + +export const walletField = 'walletLND' diff --git a/wallets/lnd/server.js b/wallets/lnd/server.js index 8d8d4a70..ab95d8aa 100644 --- a/wallets/lnd/server.js +++ b/wallets/lnd/server.js @@ -5,10 +5,6 @@ import { addWalletLog } from '@/api/resolvers/wallet' export * from 'wallets/lnd' -export const walletType = 'LND' - -export const walletField = 'walletLND' - export const testConnect = async ( { cert, macaroon, socket }, { me, models } diff --git a/wallets/server.js b/wallets/server.js index 1b47606e..b625824d 100644 --- a/wallets/server.js +++ b/wallets/server.js @@ -2,7 +2,4 @@ import * as lnd from 'wallets/lnd/server' import * as cln from 'wallets/cln/server' import * as lnAddr from 'wallets/lightning-address/server' -// worker and app import modules differently -// const resolveImport = i => i.default || i - export default [lnd, cln, lnAddr]