From ebbfd76aa4f115d557039ba871d04acf6b46428c Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Wed, 1 Nov 2023 10:13:09 +0530 Subject: [PATCH 1/2] feat: add user_agent in default request options as well --- src/extension/background-script/connectors/alby.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/extension/background-script/connectors/alby.ts b/src/extension/background-script/connectors/alby.ts index 3df2a38fd7..2d2439349b 100644 --- a/src/extension/background-script/connectors/alby.ts +++ b/src/extension/background-script/connectors/alby.ts @@ -322,8 +322,11 @@ export default class Alby implements Connector { private _getRequestOptions(): Partial { return { ...(process.env.ALBY_API_URL - ? { base_url: process.env.ALBY_API_URL } - : {}), + ? { + base_url: process.env.ALBY_API_URL, + user_agent: `lightning-browser-extension:${process.env.VERSION}`, + } + : { user_agent: `lightning-browser-extension:${process.env.VERSION}` }), }; } From 122bcf2609133fbb84ecd73208f3463fa2df7720 Mon Sep 17 00:00:00 2001 From: pavanjoshi914 Date: Wed, 1 Nov 2023 13:42:43 +0530 Subject: [PATCH 2/2] feat: add user_agent for each request --- .../background-script/connectors/alby.ts | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/extension/background-script/connectors/alby.ts b/src/extension/background-script/connectors/alby.ts index 2d2439349b..a2bf57470f 100644 --- a/src/extension/background-script/connectors/alby.ts +++ b/src/extension/background-script/connectors/alby.ts @@ -89,7 +89,7 @@ export default class Alby implements Connector { async getInvoices(): Promise { const incomingInvoices = (await this._request((client) => - client.incomingInvoices({}) + client.incomingInvoices({}, this._getRequestOptions()) )) as Invoice[]; const invoices: ConnectorInvoice[] = incomingInvoices.map( @@ -116,7 +116,7 @@ export default class Alby implements Connector { > { try { const info = await this._request((client) => - client.accountInformation({}) + client.accountInformation({}, this._getRequestOptions()) ); return { data: { @@ -132,7 +132,7 @@ export default class Alby implements Connector { async getBalance(): Promise { const { balance } = await this._request((client) => - client.accountBalance({}) + client.accountBalance({}, this._getRequestOptions()) ); return { @@ -144,9 +144,12 @@ export default class Alby implements Connector { async sendPayment(args: SendPaymentArgs): Promise { const data = await this._request((client) => - client.sendPayment({ - invoice: args.paymentRequest, - }) + client.sendPayment( + { + invoice: args.paymentRequest, + }, + this._getRequestOptions() + ) ); return { @@ -160,11 +163,14 @@ export default class Alby implements Connector { async keysend(args: KeysendArgs): Promise { const data = await this._request((client) => - client.keysend({ - destination: args.pubkey, - amount: args.amount, - customRecords: args.customRecords, - }) + client.keysend( + { + destination: args.pubkey, + amount: args.amount, + customRecords: args.customRecords, + }, + this._getRequestOptions() + ) ); return { @@ -180,7 +186,7 @@ export default class Alby implements Connector { let paid = false; try { const invoice = await this._request((client) => - client.getInvoice(args.paymentHash) + client.getInvoice(args.paymentHash, this._getRequestOptions()) ); paid = !!invoice?.settled; } catch (error) { @@ -203,10 +209,13 @@ export default class Alby implements Connector { async makeInvoice(args: MakeInvoiceArgs): Promise { const data = await this._request((client) => - client.createInvoice({ - amount: parseInt(args.amount.toString()), - description: args.memo, - }) + client.createInvoice( + { + amount: parseInt(args.amount.toString()), + description: args.memo, + }, + this._getRequestOptions() + ) ); return { @@ -218,12 +227,16 @@ export default class Alby implements Connector { } async getSwapInfo(): Promise { - const result = await this._request((client) => client.getSwapInfo()); + const result = await this._request((client) => + client.getSwapInfo(this._getRequestOptions()) + ); return result; } async createSwap(params: CreateSwapParams): Promise { - const result = await this._request((client) => client.createSwap(params)); + const result = await this._request((client) => + client.createSwap(params, this._getRequestOptions()) + ); return result; }