Skip to content

Commit

Permalink
fix errors in test
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Jul 16, 2024
1 parent a247b7f commit ef8111f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/CashuMint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,16 @@ class CashuMint {
customRequest?: typeof request
): Promise<MeltQuoteResponse> {
const requestInstance = customRequest || request;
const data = await requestInstance<MeltQuoteResponse>({
const response = await requestInstance<MeltQuoteResponse & MeltQuoteResponsePaidDeprecated>({
endpoint: joinUrls(mintUrl, '/v1/melt/bolt11'),
method: 'POST',
requestBody: meltPayload
});

const data = handleMeltQuoteResponseDeprecated(response);

if (
!isObj(data) ||
typeof data?.amount !== 'number' ||
typeof data?.fee_reserve !== 'number' ||
typeof data?.quote !== 'string' ||
typeof data?.state !== 'string' ||
!Object.values(MeltQuoteState).includes(data.state)
) {
Expand Down
8 changes: 4 additions & 4 deletions src/legacy/nut-04.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export function handleMintQuoteResponseDeprecated(
): MintQuoteResponse {
// if the response MeltQuoteResponse has a "paid" flag, we monkey patch it to the state enum
if (!response.state) {
console.log(
console.warn(
"Field 'state' not found in MintQuoteResponse. Update NUT-04 of mint: https://github.com/cashubtc/nuts/pull/141)"
);
}
if (typeof response.paid === 'boolean') {
response.state = response.paid ? MintQuoteState.PAID : MintQuoteState.UNPAID;
if (typeof response.paid === 'boolean') {
response.state = response.paid ? MintQuoteState.PAID : MintQuoteState.UNPAID;
}
}
return response;
}
8 changes: 4 additions & 4 deletions src/legacy/nut-05.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export function handleMeltQuoteResponseDeprecated(
): MeltQuoteResponse {
// if the response MeltQuoteResponse has a "paid" flag, we monkey patch it to the state enum
if (!response.state) {
console.log(
console.warn(
"Field 'state' not found in MeltQuoteResponse. Update NUT-05 of mint: https://github.com/cashubtc/nuts/pull/136)"
);
}
if (typeof response.paid === 'boolean') {
response.state = response.paid ? MeltQuoteState.PAID : MeltQuoteState.UNPAID;
if (typeof response.paid === 'boolean') {
response.state = response.paid ? MeltQuoteState.PAID : MeltQuoteState.UNPAID;
}
}
return response;
}

0 comments on commit ef8111f

Please sign in to comment.