From d30502a011e5a3c962066c5269c37a745548874b Mon Sep 17 00:00:00 2001 From: Riccardo Balbo Date: Tue, 15 Oct 2024 15:13:04 +0200 Subject: [PATCH] fix wallet filtering --- api/resolvers/wallet.js | 22 ++++++++++++++++------ wallets/index.js | 9 ++++++--- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/api/resolvers/wallet.js b/api/resolvers/wallet.js index c2fe95fe..0da5fbca 100644 --- a/api/resolvers/wallet.js +++ b/api/resolvers/wallet.js @@ -181,13 +181,23 @@ const resolvers = { throw new GqlAuthenticationError() } + const filter = { + userId: me.id + } + + if (includeReceivers && includeSenders) { + filter.OR = [ + { canReceive: true }, + { canSend: true } + ] + } else if (includeReceivers) { + filter.canReceive = true + } else if (includeSenders) { + filter.canSend = true + } + return await models.wallet.findMany({ - where: { - userId: me.id, - canReceive: includeReceivers, - canSend: includeSenders, - enabled: onlyEnabled !== undefined ? onlyEnabled : undefined - }, + where: filter, orderBy: { priority: 'desc' } diff --git a/wallets/index.js b/wallets/index.js index fd0eecbd..a0987ef7 100644 --- a/wallets/index.js +++ b/wallets/index.js @@ -34,8 +34,8 @@ export function useWallet (name) { // .filter(w => w.enabled && w.canSend)// filtered by the server // .sort((a, b) => b.priority - a.priority) // already priority sorted by the server .map(w => getWalletByType(w.type)) - .filter(w => !w.isAvailable || w.isAvailable())[0] - name = bestWalletDef?.name + .filter(w => !w.isAvailable || w.isAvailable()) + name = bestWalletDef?.[0]?.name } const walletDef = getWalletByName(name) @@ -113,7 +113,10 @@ export function useWallet (name) { }, [deleteLogs]) const wallet = useMemo(() => { - if (!walletDef) return {} + if (!walletDef) { + console.log(name) + return {} + } const wallet = { ...walletDef }