Skip to content

Commit

Permalink
Infer walletName from walletType in upsertWallet
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Apr 15, 2024
1 parent 46fd0bf commit 0a8b615
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions api/resolvers/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,10 @@ export default {
data.macaroon = ensureB64(data.macaroon)
data.cert = ensureB64(data.cert)

const walletName = 'walletLND'
const walletType = 'LND'
return await upsertWallet(
{
schema: LNDAutowithdrawSchema,
walletName,
walletType,
testConnect: async ({ cert, macaroon, socket }) => {
try {
Expand Down Expand Up @@ -471,12 +469,10 @@ export default {
upsertWalletCLN: async (parent, { settings, ...data }, { me, models }) => {
data.cert = ensureB64(data.cert)

const walletName = 'walletCLN'
const walletType = 'CLN'
return await upsertWallet(
{
schema: CLNAutowithdrawSchema,
walletName,
walletType,
testConnect: async ({ socket, rune, cert }) => {
try {
Expand All @@ -500,12 +496,10 @@ export default {
{ settings, data }, { me, models })
},
upsertWalletLNAddr: async (parent, { settings, ...data }, { me, models }) => {
const walletName = 'walletLightningAddress'
const walletType = 'LIGHTNING_ADDRESS'
return await upsertWallet(
{
schema: lnAddrAutowithdrawSchema,
walletName,
walletType,
testConnect: async ({ address }) => {
const options = await lnAddrOptions(address)
Expand Down Expand Up @@ -571,7 +565,7 @@ export const addWalletLog = async ({ wallet, level, message }, { me, models }) =
}

async function upsertWallet (
{ schema, walletName, walletType, testConnect }, { settings, data }, { me, models }) {
{ schema, walletType, testConnect }, { settings, data }, { me, models }) {
if (!me) {
throw new GraphQLError('you must be logged in', { extensions: { code: 'UNAUTHENTICATED' } })
}
Expand Down Expand Up @@ -614,6 +608,9 @@ async function upsertWallet (
}))
}

const walletName = walletType === 'LND'
? 'walletLND'
: walletType === 'CLN' ? 'walletCLN' : 'walletLightningAddress'
if (id) {
txs.push(
models.wallet.update({
Expand Down

0 comments on commit 0a8b615

Please sign in to comment.