fix(Rates): Various fixes

This commit is contained in:
Jim Hamill
2025-04-30 06:27:53 +00:00
parent 71281e153a
commit 6cf2cceb4c
3 changed files with 9 additions and 10 deletions
+3 -3
View File
@@ -32,7 +32,7 @@ export class RatesBitPay extends BaseRates {
// Default to 60 second refresh.
refreshIntervalMs: 60_000,
// Default to browser/node fetch function
fetch: fetch,
fetch: (...args) => globalThis.fetch(...args),
// Merge any user-specified options in.
...opts,
};
@@ -98,7 +98,7 @@ export class RatesBitPay extends BaseRates {
: `${this.opts.baseURL}/rates/${cryptoCode.toLowerCase()}`;
// Fetch from BitPay API
const ratesRes = await this.opts.fetch(endpoint, {});
const ratesRes = await this.opts.fetch(endpoint);
// If request failed, throw an error
if (!ratesRes.ok) {
@@ -170,7 +170,7 @@ export type RatesBitPayOptions = {
/**
* Optional fetch-like function (e.g. global fetch) for HTTP calls.
*/
fetch: (url: string, options: RequestInit) => Promise<Response>;
fetch: (url: string, options?: RequestInit) => Promise<Response>;
};
// The rates payload schema we receive from BitPay's API.
+2 -3
View File
@@ -32,7 +32,7 @@ export class RatesCoinbase extends BaseRates {
// Default to 60 second refresh.
refreshIntervalMs: 60_000,
// Default to browser/node fetch function
fetch: fetch,
fetch: (...args) => globalThis.fetch(...args),
// Merge any user-specified options in.
...opts,
};
@@ -101,7 +101,6 @@ export class RatesCoinbase extends BaseRates {
// Fetch from Coinbase API.
const priceRes = await this.opts.fetch(
`${this.opts.baseURL}/v2/exchange-rates?currency=${currencyCode}`,
{},
);
// If request failed, throw an error.
@@ -163,7 +162,7 @@ export type RatesCoinbaseOptions = {
/**
* Optional fetch-like function (e.g. global fetch) for HTTP calls.
*/
fetch: (url: string, options: RequestInit) => Promise<Response>;
fetch: (url: string, options?: RequestInit) => Promise<Response>;
};
// The rates payload schema we receive from Coinbase's API.
+4 -4
View File
@@ -24,7 +24,7 @@ export class RatesComposite extends BaseRates {
constructor(
private adapters: BaseRates[],
private policy: RatesCompositePolicy = ratesAveragePolicy,
private refreshIntervalMs: number = 1000,
private refreshIntervalMs: number = 60000,
) {
super();
@@ -36,9 +36,6 @@ export class RatesComposite extends BaseRates {
* Start all rate adapters and setup event listeners
*/
public async start(): Promise<void> {
// Start all adapters
await Promise.all(this.adapters.map((adapter) => adapter.start()));
// Setup event listeners for all adapters
for (let i = 0; i < this.adapters.length; i++) {
const adapter = this.adapters[i];
@@ -59,6 +56,9 @@ export class RatesComposite extends BaseRates {
this.unsubscribeFunctions.push(unsubscribe);
}
// Start all adapters
await Promise.all(this.adapters.map((adapter) => adapter.start()));
// Start periodic refresh to emit combined rates
this.startPeriodicRefresh();
}