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
This commit is contained in:
ekzyis 2024-07-16 22:08:41 +02:00
parent bbcfc2fada
commit b777fdcddc
11 changed files with 24 additions and 38 deletions

View File

@ -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 })
}
}

View File

@ -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,

View File

@ -37,7 +37,7 @@ export default function WalletSettings () {
<CenterLayout>
<h2 className='pb-2'>{wallet.card.title}</h2>
<h6 className='text-muted text-center pb-3'><Text>{wallet.card.subtitle}</Text></h6>
{!wallet.server && <WalletSecurityBanner />}
{!wallet.walletType && <WalletSecurityBanner />}
<Form
initial={initial}
schema={wallet.schema}
@ -65,7 +65,7 @@ export default function WalletSettings () {
}}
>
<WalletFields wallet={wallet} />
{wallet.server
{wallet.walletType
? <AutowithdrawSettings wallet={wallet} />
: (
<ClientCheckbox

View File

@ -40,3 +40,7 @@ export const card = {
}
export const schema = CLNAutowithdrawSchema
export const walletType = 'CLN'
export const walletField = 'walletCLN'

View File

@ -4,10 +4,6 @@ import { addWalletLog } from '@/api/resolvers/wallet'
export * from 'wallets/cln'
export const walletType = 'CLN'
export const walletField = 'walletCLN'
export const testConnect = async (
{ socket, rune, cert },
{ me, models }

View File

@ -123,7 +123,7 @@ function useConfig (wallet) {
const [serverConfig, setServerConfig, clearServerConfig] = useServerConfig(wallet)
const hasLocalConfig = !!wallet?.sendPayment
const hasServerConfig = !!wallet?.server
const hasServerConfig = !!wallet?.walletType
const config = {
// only include config if it makes sense for this wallet
@ -161,7 +161,7 @@ function useServerConfig (wallet) {
const client = useApolloClient()
const me = useMe()
const { data, refetch: refetchConfig } = useQuery(WALLET_BY_TYPE, { variables: { type: wallet?.server?.walletType }, skip: !wallet?.server })
const { data, refetch: refetchConfig } = useQuery(WALLET_BY_TYPE, { variables: { type: wallet?.walletType }, skip: !wallet?.walletType })
const walletId = data?.walletByType?.id
const serverConfig = {
@ -217,9 +217,7 @@ function useServerConfig (wallet) {
}
function generateMutation (wallet) {
const { walletField } = wallet.server
const resolverName = generateResolverName(walletField)
const resolverName = generateResolverName(wallet.walletField)
let headerArgs = '$id: ID, '
headerArgs += wallet.fields.map(f => {
@ -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) {

View File

@ -19,3 +19,7 @@ export const card = {
}
export const schema = lnAddrAutowithdrawSchema
export const walletType = 'LIGHTNING_ADDRESS'
export const walletField = 'walletLightningAddress'

View File

@ -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 }

View File

@ -41,3 +41,7 @@ export const card = {
}
export const schema = LNDAutowithdrawSchema
export const walletType = 'LND'
export const walletField = 'walletLND'

View File

@ -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 }

View File

@ -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]