Skip to content

Commit

Permalink
Merge pull request cashubtc#125 from Dayvvo/trailing-slash-handle-fix
Browse files Browse the repository at this point in the history
Fix: Handle trailing slashes in mint urls supplied to the CashuMint class
  • Loading branch information
gandlafbtc authored May 20, 2024
2 parents c69d358 + 0fd4266 commit ebd4c18
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/CashuMint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
MeltQuoteResponse
} from './model/types/index.js';
import request from './request.js';
import { isObj, joinUrls } from './utils.js';
import { isObj, joinUrls, sanitizeUrl } from './utils.js';

/**
* Class represents Cashu Mint API. This class contains Lower level functions that are implemented by CashuWallet.
Expand All @@ -29,7 +29,10 @@ class CashuMint {
* @param _mintUrl requires mint URL to create this object
* @param _customRequest if passed, use custom request implementation for network communication with the mint
*/
constructor(private _mintUrl: string, private _customRequest?: typeof request) {}
constructor(private _mintUrl: string, private _customRequest?: typeof request) {
this._mintUrl = sanitizeUrl(_mintUrl);
this._customRequest = _customRequest;
}

get mintUrl() {
return this._mintUrl;
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ export function joinUrls(...parts: Array<string>): string {
return parts.map((part) => part.replace(/(^\/+|\/+$)/g, '')).join('/');
}

export function sanitizeUrl(url: string): string {
return url.replace(/\/$/, '');
}

export function decodeInvoice(bolt11Invoice: string): InvoiceData {
const invoiceData: InvoiceData = {} as InvoiceData;
const decodeResult = decode(bolt11Invoice);
Expand Down

0 comments on commit ebd4c18

Please sign in to comment.