mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
fix: return mints from the wallet, not just the ones from kind 7375
This commit is contained in:
parent
d055c80abe
commit
04d710b1b8
2 changed files with 15 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ import { CashuMint, CashuWallet, MintQuoteState, Proof } from '@cashu/cashu-ts';
|
|||
import { confRequiredMw } from '@ditto/api/middleware';
|
||||
import { Hono } from '@hono/hono';
|
||||
import { generateSecretKey, getPublicKey } from 'nostr-tools';
|
||||
import { NSchema as n } from '@nostrify/nostrify';
|
||||
import { bytesToString, stringToBytes } from '@scure/base';
|
||||
import { z } from 'zod';
|
||||
|
||||
|
|
@ -246,7 +247,12 @@ app.get('/wallet', requireNip44Signer, swapNutzapsMiddleware, async (c) => {
|
|||
return c.json({ error: 'Wallet not found' }, 404);
|
||||
}
|
||||
|
||||
const decryptedContent: string[][] = JSON.parse(await signer.nip44.decrypt(pubkey, event.content));
|
||||
const { data: decryptedContent, success } = n.json().pipe(z.string().array().array()).safeParse(
|
||||
await signer.nip44.decrypt(pubkey, event.content),
|
||||
);
|
||||
if (!success) {
|
||||
return c.json({ error: 'Could not decrypt wallet content' }, 422);
|
||||
}
|
||||
|
||||
const privkey = decryptedContent.find(([value]) => value === 'privkey')?.[1];
|
||||
if (!privkey || !isNostrId(privkey)) {
|
||||
|
|
@ -258,6 +264,13 @@ app.get('/wallet', requireNip44Signer, swapNutzapsMiddleware, async (c) => {
|
|||
let balance = 0;
|
||||
const mints: string[] = [];
|
||||
|
||||
for (const tag of decryptedContent) {
|
||||
const isMint = tag[0] === 'mint';
|
||||
if (isMint) {
|
||||
mints.push(tag[1]);
|
||||
}
|
||||
}
|
||||
|
||||
const tokens = await store.query([{ authors: [pubkey], kinds: [7375] }], { signal });
|
||||
for (const token of tokens) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ import { NostrEvent, NostrFilter, NostrSigner, NSchema as n, NStore } from '@nos
|
|||
import { SetRequired } from 'type-fest';
|
||||
import { stringToBytes } from '@scure/base';
|
||||
import { logi } from '@soapbox/logi';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { isNostrId } from '@/utils.ts';
|
||||
import { errorJson } from '@/utils/log.ts';
|
||||
import { createEvent } from '@/utils/api.ts';
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* Swap nutzaps into wallet (create new events) if the user has a wallet, otheriwse, just fallthrough.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue