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 // FIXME: this throws
// TypeError: import_server.default is not iterable // TypeError: import_server.default is not iterable
const w of walletDefs) { const w of walletDefs) {
const { // app and worker import file differently
schema, const { schema, walletType, walletField, testConnect } = w.default || w
walletType, walletField, testConnect
// app and worker import file differently
} = w.default || w
const resolverName = generateResolverName(walletField) const resolverName = generateResolverName(walletField)
console.log(resolverName) console.log(resolverName)
resolvers.Mutation[resolverName] = async (parent, { settings, ...data }, { me, models }) => { resolvers.Mutation[resolverName] = async (parent, { settings, ...data }, { me, models }) => {
@ -34,13 +31,7 @@ function injectResolvers (resolvers) {
schema, schema,
wallet: { field: walletField, type: walletType }, wallet: { field: walletField, type: walletType },
testConnect: (data) => testConnect: (data) =>
testConnect( testConnect(data, { me, models })
data,
{
me,
models
}
)
}, { settings, data }, { me, models }) }, { settings, data }, { me, models })
} }
} }

View File

@ -204,8 +204,8 @@ export const WalletLoggerProvider = ({ children }) => {
}, [saveLog]) }, [saveLog])
const deleteLogs = useCallback(async (wallet) => { const deleteLogs = useCallback(async (wallet) => {
if (!wallet || wallet.server) { if (!wallet || wallet.walletType) {
await deleteServerWalletLogs({ variables: { wallet: wallet?.server?.walletType } }) await deleteServerWalletLogs({ variables: { wallet: wallet?.walletType } })
} }
if (!wallet || wallet.sendPayment) { if (!wallet || wallet.sendPayment) {
const tx = idb.current.transaction(idbStoreName, 'readwrite') 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 // don't store logs for receiving wallets on client since logs are stored on server
if (wallet.server) return if (wallet.walletType) return
// TODO: // TODO:
// also send this to us if diagnostics was enabled, // also send this to us if diagnostics was enabled,

View File

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

View File

@ -40,3 +40,7 @@ export const card = {
} }
export const schema = CLNAutowithdrawSchema 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 * from 'wallets/cln'
export const walletType = 'CLN'
export const walletField = 'walletCLN'
export const testConnect = async ( export const testConnect = async (
{ socket, rune, cert }, { socket, rune, cert },
{ me, models } { me, models }

View File

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

View File

@ -19,3 +19,7 @@ export const card = {
} }
export const schema = lnAddrAutowithdrawSchema 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 * from 'wallets/lightning-address'
export const walletType = 'LIGHTNING_ADDRESS'
export const walletField = 'walletLightningAddress'
export const testConnect = async ( export const testConnect = async (
{ address }, { address },
{ me, models, addWalletLog } { me, models, addWalletLog }

View File

@ -41,3 +41,7 @@ export const card = {
} }
export const schema = LNDAutowithdrawSchema 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 * from 'wallets/lnd'
export const walletType = 'LND'
export const walletField = 'walletLND'
export const testConnect = async ( export const testConnect = async (
{ cert, macaroon, socket }, { cert, macaroon, socket },
{ me, models } { me, models }

View File

@ -2,7 +2,4 @@ import * as lnd from 'wallets/lnd/server'
import * as cln from 'wallets/cln/server' import * as cln from 'wallets/cln/server'
import * as lnAddr from 'wallets/lightning-address/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] export default [lnd, cln, lnAddr]