From 30e4a4c0abd3f1e1398bbcac80a017f98f0c5c11 Mon Sep 17 00:00:00 2001 From: minibits-cash Date: Thu, 18 Jul 2024 16:18:53 +0200 Subject: [PATCH] Upgrade to cashu-ts v1.0.0-minibits --- package.json | 4 ++-- src/screens/TransferScreen.tsx | 10 +++++----- src/services/cashuMintClient.ts | 34 ++++++++++++++++---------------- src/services/wallet/topupTask.ts | 2 +- src/services/walletService.ts | 24 +++++++++++++++------- yarn.lock | 6 +++--- 6 files changed, 45 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index ce0a7e73..a2f4e55c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minibits_wallet", - "version": "0.1.8-beta.36", + "version": "0.1.8-beta.37", "private": true, "scripts": { "android:clean": "cd android && ./gradlew clean", @@ -19,7 +19,7 @@ "postinstall": "patch-package --exclude 'nothing'" }, "dependencies": { - "@cashu/cashu-ts": "minibits-cash/cashu-ts#v1.0.0-rc.9-minibits", + "@cashu/cashu-ts": "minibits-cash/cashu-ts#1.0.0-minibits", "@fortawesome/fontawesome-svg-core": "^6.5.2", "@fortawesome/free-brands-svg-icons": "^6.5.2", "@fortawesome/free-regular-svg-icons": "^6.5.2", diff --git a/src/screens/TransferScreen.tsx b/src/screens/TransferScreen.tsx index 4b8e3d71..a9a3fd01 100644 --- a/src/screens/TransferScreen.tsx +++ b/src/screens/TransferScreen.tsx @@ -276,12 +276,12 @@ useFocusEffect( useEffect(() => { - const getMeltQuote = async function () { + const createMeltQuote = async function () { try { - log.trace('[getMeltQuote]', {mintBalanceToTransferFrom}) + log.trace('[createMeltQuote]', {mintBalanceToTransferFrom}) if (!mintBalanceToTransferFrom || !encodedInvoice) { log.trace( - '[getMeltQuote]', + '[createMeltQuote]', 'Not yet ready to request melt quote or melt quote already exists... exiting', {mintBalanceToTransferFrom, encodedInvoice} @@ -290,7 +290,7 @@ useEffect(() => { } setIsLoading(true) - const quote = await MintClient.getLightningMeltQuote( + const quote = await MintClient.createLightningMeltQuote( mintBalanceToTransferFrom.mintUrl, unit, encodedInvoice, @@ -320,7 +320,7 @@ useEffect(() => { } } - getMeltQuote() + createMeltQuote() }, [mintBalanceToTransferFrom]) diff --git a/src/services/cashuMintClient.ts b/src/services/cashuMintClient.ts index a4199b95..304903f3 100644 --- a/src/services/cashuMintClient.ts +++ b/src/services/cashuMintClient.ts @@ -338,19 +338,19 @@ const getSpentOrPendingProofsFromMint = async function ( -const getLightningMeltQuote = async function ( +const createLightningMeltQuote = async function ( mintUrl: string, unit: MintUnit, encodedInvoice: string, ) { try { const cashuMint = getMint(mintUrl) - const lightningQuote: MeltQuoteResponse = await cashuMint.meltQuote({ + const lightningQuote: MeltQuoteResponse = await cashuMint.createMeltQuote({ unit, request: encodedInvoice }) - log.info('[getLightningMeltQuote]', {mintUrl, unit, encodedInvoice}, {lightningQuote}) + log.info('[createLightningMeltQuote]', {mintUrl, unit, encodedInvoice}, {lightningQuote}) return lightningQuote @@ -362,7 +362,7 @@ const getLightningMeltQuote = async function ( message, { message: e.message, - caller: 'getLightningMeltQuote', + caller: 'createLightningMeltQuote', request: {mintUrl, unit, encodedInvoice}, } ) @@ -415,7 +415,7 @@ const payLightningMelt = async function ( -const getBolt11MintQuote = async function ( +const createLightningMintQuote = async function ( mintUrl: string, unit: MintUnit, amount: number, @@ -425,12 +425,12 @@ const getBolt11MintQuote = async function ( const { request: encodedInvoice, quote: mintQuote, - } = await cashuMint.mintQuote({ + } = await cashuMint.createMintQuote({ unit, amount }) - log.info('[getBolt11MintQuote]', {encodedInvoice, mintQuote}) + log.info('[createLightningMintQuote]', {encodedInvoice, mintQuote}) return { encodedInvoice, @@ -444,7 +444,7 @@ const getBolt11MintQuote = async function ( message, { message: e.message, - caller: 'getBolt11MintQuote', + caller: 'createLightningMintQuote', mintUrl, } ) @@ -452,7 +452,7 @@ const getBolt11MintQuote = async function ( } -const getBolt11MintQuoteIsPaid = async function ( +const checkLightningMintQuote = async function ( mintUrl: string, quote: string, ) { @@ -461,17 +461,17 @@ const getBolt11MintQuoteIsPaid = async function ( const { request: encodedInvoice, quote: mintQuote, - paid: isPaid - } = await cashuMint.getMintQuote( + state, + } = await cashuMint.checkMintQuote( quote ) - log.info('[getBolt11MintQuoteIsPaid]', {encodedInvoice, mintQuote, isPaid}) + log.info('[checkLightningMintQuote]', {encodedInvoice, mintQuote, state}) return { encodedInvoice, mintQuote, - isPaid + state } } catch (e: any) { let message = 'The mint could not return the state of a mint quote.' @@ -481,7 +481,7 @@ const getBolt11MintQuoteIsPaid = async function ( message, { message: e.message, - caller: 'getBolt11MintQuoteIsPaid', + caller: 'checkLightningMintQuote', mintUrl, } ) @@ -613,10 +613,10 @@ export const MintClient = { receiveFromMint, sendFromMint, getSpentOrPendingProofsFromMint, - getBolt11MintQuote, - getBolt11MintQuoteIsPaid, + createLightningMintQuote, + checkLightningMintQuote, mintProofs, - getLightningMeltQuote, + createLightningMeltQuote, payLightningMelt, restore, getMintInfo, diff --git a/src/services/wallet/topupTask.ts b/src/services/wallet/topupTask.ts index 07558703..695ff770 100644 --- a/src/services/wallet/topupTask.ts +++ b/src/services/wallet/topupTask.ts @@ -59,7 +59,7 @@ export const topupTask = async function ( const storedTransaction: TransactionRecord = await transactionsStore.addTransaction(newTransaction) transactionId = storedTransaction.id as number - const {encodedInvoice, mintQuote} = await MintClient.getBolt11MintQuote(mintUrl, unit, amountToTopup) + const {encodedInvoice, mintQuote} = await MintClient.createLightningMintQuote(mintUrl, unit, amountToTopup) const decodedInvoice = LightningUtils.decodeInvoice(encodedInvoice) const {amount, payment_hash, expiry, timestamp} = LightningUtils.getInvoiceData(decodedInvoice) diff --git a/src/services/walletService.ts b/src/services/walletService.ts index d8fac1eb..d57ea24f 100644 --- a/src/services/walletService.ts +++ b/src/services/walletService.ts @@ -13,7 +13,7 @@ import {LightningUtils} from './lightning/lightningUtils' import AppError, {Err} from '../utils/AppError' import {MintBalance, MintStatus} from '../models/Mint' import {Token} from '../models/Token' -import {MeltQuoteResponse, type Proof as CashuProof} from '@cashu/cashu-ts' +import {MeltQuoteResponse, MintQuoteState, type Proof as CashuProof} from '@cashu/cashu-ts' import {Mint} from '../models/Mint' import {pollerExists, stopPolling} from '../utils/poller' import EventEmitter from '../utils/eventEmitter' @@ -768,13 +768,13 @@ const _handlePendingTopupTask = async function (params: {paymentRequest: Payment log.trace('[_handlePendingTopupTask]', 'countOfInFlightProofs', countOfInFlightProofs) // check is quote has been paid - const { isPaid, mintQuote: quote } = await MintClient.getBolt11MintQuoteIsPaid(mint!, mintQuote) + const { state, mintQuote: quote } = await MintClient.checkLightningMintQuote(mint!, mintQuote) if (quote !== mintQuote) { throw new AppError(Err.VALIDATION_ERROR, 'Returned quote is different then the one requested', {mintUrl: mint, quote, mintQuote}) } - if (isPaid !== true) { + if (state !== MintQuoteState.PAID) { log.trace('[_handlePendingTopupTask] Quote not paid', {mintUrl: mint, mintQuote}) if (isBefore(pr.expiresAt as Date, new Date())) { @@ -928,13 +928,23 @@ const handleClaim = async function (): Promise { log.info('[handleClaim] start') const {walletId, seedHash, pubkey} = walletProfileStore + let recoveredWalletId: string | null = null - - if(!walletId || !seedHash || !pubkey) { - throw new AppError(Err.VALIDATION_ERROR, 'Skipping claim of ecash received to your lightning address, missing profile data', {walletId, seedHash, pubkey}) + if(!seedHash || !pubkey) { + throw new AppError(Err.VALIDATION_ERROR, 'Skipping claim of ecash received to your lightning address, missing profile data. Reinstall wallet to fix it.', {walletId, seedHash, pubkey}) } - const claimedInvoices = await MinibitsClient.createClaim(walletId, seedHash, pubkey) + if(!walletId) { + // fix immediately in case only walletId missing in walletProfile + const profile = await MinibitsClient.getWalletProfileBySeedHash(seedHash) + + if(profile) { + recoveredWalletId = profile.walletId + walletProfileStore.setWalletId(recoveredWalletId) + } + } + + const claimedInvoices = await MinibitsClient.createClaim(walletId || recoveredWalletId as string, seedHash, pubkey) if(claimedInvoices.length === 0) { log.debug('[handleClaim] No claimed invoices returned from server...') diff --git a/yarn.lock b/yarn.lock index 22a7571f..ae407b35 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1202,9 +1202,9 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@cashu/cashu-ts@minibits-cash/cashu-ts#v1.0.0-rc.9-minibits": - version "1.0.0-rc.9-minibits" - resolved "https://codeload.github.com/minibits-cash/cashu-ts/tar.gz/9415955cce68ef86c653757b0599c77634085281" +"@cashu/cashu-ts@minibits-cash/cashu-ts#1.0.0-minibits": + version "1.0.0-minibits" + resolved "https://codeload.github.com/minibits-cash/cashu-ts/tar.gz/95cd37801f54700bed1b84113a774bd23f36aecb" dependencies: "@cashu/crypto" "^0.2.6" "@noble/curves" "^1.3.0"