Skip to content

Commit

Permalink
zbd send only attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Jan 6, 2025
1 parent 2b5c7bf commit 0949059
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 139 deletions.
3 changes: 0 additions & 3 deletions fragments/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ export const WALLET_FIELDS = gql`
apiKeyRecv
currencyRecv
}
... on WalletZebedee {
gamerTagId
}
}
}
`
Expand Down
24 changes: 0 additions & 24 deletions prisma/migrations/20241219120508_zebedee_attachment/migration.sql

This file was deleted.

2 changes: 2 additions & 0 deletions prisma/migrations/20250106164328_zebedee_sender/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "WalletType" ADD VALUE 'ZEBEDEE';
10 changes: 0 additions & 10 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ model Wallet {
walletNWC WalletNWC?
walletPhoenixd WalletPhoenixd?
walletBlink WalletBlink?
walletZebedee WalletZebedee?
vaultEntries VaultEntry[] @relation("VaultEntries")
withdrawals Withdrawl[]
Expand Down Expand Up @@ -327,15 +326,6 @@ model WalletPhoenixd {
secondaryPassword String?
}

model WalletZebedee {
id Int @id @default(autoincrement())
walletId Int @unique
wallet Wallet @relation(fields: [walletId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
gamerTagId String?
}

model Mute {
muterId Int
mutedId Int
Expand Down
2 changes: 1 addition & 1 deletion wallets/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import * as lnbits from '@/wallets/lnbits/server'
import * as nwc from '@/wallets/nwc/server'
import * as phoenixd from '@/wallets/phoenixd/server'
import * as blink from '@/wallets/blink/server'
import * as zebedee from '@/wallets/zebedee/server'

// we import only the metadata of client side wallets
import * as lnc from '@/wallets/lnc'
import * as webln from '@/wallets/webln'
import * as zebedee from '@/wallets/zebedee'

import { walletLogger } from '@/api/resolvers/wallet'
import walletDefs from '@/wallets/server'
Expand Down
57 changes: 31 additions & 26 deletions wallets/zebedee/client.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { API_URL, PREIMAGE_AWAIT_TIMEOUT_MS } from '@/wallets/zebedee'
import { API_URL } from '@/wallets/zebedee'
import { assertContentTypeJson } from '@/lib/url'
import { callWithTimeout } from '@/lib/time'
import { fetchWithTimeout } from '@/lib/fetch'

export * from '@/wallets/zebedee'

export async function testSendPayment ({ apiKey }, { signal }) {
Expand All @@ -19,45 +16,53 @@ export async function sendPayment (bolt11, { apiKey }, { signal }) {
}

async function waitForPreimage (id, { apiKey }, { signal }) {
return await callWithTimeout(async () => {
let preimage
while (true) {
const res = await apiCall('payments/{id}', { body: { id }, apiKey, method: 'GET' }, { signal })
preimage = res?.data?.preimage
if (preimage) break
await new Promise(resolve => setTimeout(resolve, 10))
}
return preimage
}, PREIMAGE_AWAIT_TIMEOUT_MS)
while (!signal.aborted) {
const res = await apiCall('payments/{id}', { body: { id }, apiKey, method: 'GET' }, { signal })

// return preimage if it's available
const preimage = res?.data?.preimage
if (preimage) return preimage

// wait a before checking again
await new Promise(resolve => setTimeout(resolve, 30))
}
return null
}

export async function apiCall (api, { body, apiKey, method = 'POST' }, { signal }) {
const headers = {
apikey: apiKey,
'Content-Type': 'application/json'
}
// if get request, put params into the url
if (method === 'GET' && body) {
for (const [k, v] of Object.entries(body)) {
api = api.replace('{' + k + '}', v)
api = api.replace(`{${k}}`, v)
}
}
const res = await fetchWithTimeout(API_URL + api, {

const res = await fetch(API_URL + api, {
method,
headers,
headers: {
apikey: apiKey,
'Content-Type': 'application/json'
},
signal,
body: method === 'POST' ? JSON.stringify(body) : undefined
})
// https://zbd.dev/api-reference/errors
if (res.status !== 200) {

// Catch errors
// ref: https://zbd.dev/api-reference/errors
if (res.status < 200 || res.status > 299) {
// try to extract the error message from the response
let error
try {
assertContentTypeJson(res)
const json = await res.json()
if (json?.message) error = json.message
} catch (e) {
error = res.statusText || 'error ' + res.status
console.log('failed to parse error', e)
}
throw new Error(error)
// throw the error, if we don't have one, we try to use the request status
throw new Error(error ?? (res.statusText || `error ${res.status}`))
}
return res.json()

assertContentTypeJson(res)
return await res.json()
}
18 changes: 1 addition & 17 deletions wallets/zebedee/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { string } from '@/lib/yup'

export const PREIMAGE_AWAIT_TIMEOUT_MS = 1_200
export const STATIC_CHARGE_URL = 'https://api.zebedee.io/v0/process-static-charges/'
export const DASHBOARD_URL = 'https://dashboard.zebedee.io/'
export const GAMER_TAG_LNADDR_BASEURL = 'https://zbd.gg/.well-known/lnurlp/'
export const API_URL = 'https://api.zebedee.io/v0/'
export const ZEBEDEE_LNDOMAIN = 'zbd.gg'

export const name = 'zebedee'
export const walletType = 'ZEBEDEE'
Expand All @@ -19,24 +15,12 @@ export const fields = [
optional: 'for sending',
help: `you can get an API key from [Zebedee Dashboard](${DASHBOARD_URL}) from \n\`Project->API->Live\``,
clientOnly: true,
requiredWithout: 'gamerTagId',
validate: string()
},
{
name: 'gamerTagId',
label: 'gamer tag or id',
type: 'text',
optional: 'for receiving',
help: `you can find your Gamertag in the [Zebedee Dashboard](${DASHBOARD_URL}) under \n\`Account->Gamertag\`\n section, or in the Zebedee app on the Wallet card.\nNote: You can also use your \`@${ZEBEDEE_LNDOMAIN}\` Lightning address here.`,
serverOnly: true,
requiredWithout: 'apiKey',
validate: string()
validate: string().min(8, 'invalid api key').max(64, 'api key is too long')
}
]

export const card = {
title: 'Zebedee',
subtitle: 'use [Zebedee](https://zebedee.io) for payments',
image: { src: '/wallets/zbd.svg' }

}
58 changes: 0 additions & 58 deletions wallets/zebedee/server.js

This file was deleted.

0 comments on commit 0949059

Please sign in to comment.