Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add user_agent in default request options as well #2837

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 36 additions & 20 deletions src/extension/background-script/connectors/alby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class Alby implements Connector {

async getInvoices(): Promise<GetInvoicesResponse> {
const incomingInvoices = (await this._request((client) =>
client.incomingInvoices({})
client.incomingInvoices({}, this._getRequestOptions())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pavanjoshi914 can you check if we can pass these options to the client so they don't need to be provided in every single request? best to keep it DRY

)) as Invoice[];

const invoices: ConnectorInvoice[] = incomingInvoices.map(
Expand All @@ -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: {
Expand All @@ -132,7 +132,7 @@ export default class Alby implements Connector {

async getBalance(): Promise<GetBalanceResponse> {
const { balance } = await this._request((client) =>
client.accountBalance({})
client.accountBalance({}, this._getRequestOptions())
);

return {
Expand All @@ -144,9 +144,12 @@ export default class Alby implements Connector {

async sendPayment(args: SendPaymentArgs): Promise<SendPaymentResponse> {
const data = await this._request((client) =>
client.sendPayment({
invoice: args.paymentRequest,
})
client.sendPayment(
{
invoice: args.paymentRequest,
},
this._getRequestOptions()
)
);

return {
Expand All @@ -160,11 +163,14 @@ export default class Alby implements Connector {

async keysend(args: KeysendArgs): Promise<SendPaymentResponse> {
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 {
Expand All @@ -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) {
Expand All @@ -203,10 +209,13 @@ export default class Alby implements Connector {

async makeInvoice(args: MakeInvoiceArgs): Promise<MakeInvoiceResponse> {
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 {
Expand All @@ -218,12 +227,16 @@ export default class Alby implements Connector {
}

async getSwapInfo(): Promise<SwapInfoResponse> {
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<CreateSwapResponse> {
const result = await this._request((client) => client.createSwap(params));
const result = await this._request((client) =>
client.createSwap(params, this._getRequestOptions())
);
return result;
}

Expand Down Expand Up @@ -322,8 +335,11 @@ export default class Alby implements Connector {
private _getRequestOptions(): Partial<RequestOptions> {
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}` }),
};
}

Expand Down
Loading