fix(Rates): Various fixes
This commit is contained in:
@@ -32,7 +32,7 @@ export class RatesBitPay extends BaseRates {
|
|||||||
// Default to 60 second refresh.
|
// Default to 60 second refresh.
|
||||||
refreshIntervalMs: 60_000,
|
refreshIntervalMs: 60_000,
|
||||||
// Default to browser/node fetch function
|
// Default to browser/node fetch function
|
||||||
fetch: fetch,
|
fetch: (...args) => globalThis.fetch(...args),
|
||||||
// Merge any user-specified options in.
|
// Merge any user-specified options in.
|
||||||
...opts,
|
...opts,
|
||||||
};
|
};
|
||||||
@@ -98,7 +98,7 @@ export class RatesBitPay extends BaseRates {
|
|||||||
: `${this.opts.baseURL}/rates/${cryptoCode.toLowerCase()}`;
|
: `${this.opts.baseURL}/rates/${cryptoCode.toLowerCase()}`;
|
||||||
|
|
||||||
// Fetch from BitPay API
|
// 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 request failed, throw an error
|
||||||
if (!ratesRes.ok) {
|
if (!ratesRes.ok) {
|
||||||
@@ -170,7 +170,7 @@ export type RatesBitPayOptions = {
|
|||||||
/**
|
/**
|
||||||
* Optional fetch-like function (e.g. global fetch) for HTTP calls.
|
* 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.
|
// The rates payload schema we receive from BitPay's API.
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export class RatesCoinbase extends BaseRates {
|
|||||||
// Default to 60 second refresh.
|
// Default to 60 second refresh.
|
||||||
refreshIntervalMs: 60_000,
|
refreshIntervalMs: 60_000,
|
||||||
// Default to browser/node fetch function
|
// Default to browser/node fetch function
|
||||||
fetch: fetch,
|
fetch: (...args) => globalThis.fetch(...args),
|
||||||
// Merge any user-specified options in.
|
// Merge any user-specified options in.
|
||||||
...opts,
|
...opts,
|
||||||
};
|
};
|
||||||
@@ -101,7 +101,6 @@ export class RatesCoinbase extends BaseRates {
|
|||||||
// Fetch from Coinbase API.
|
// Fetch from Coinbase API.
|
||||||
const priceRes = await this.opts.fetch(
|
const priceRes = await this.opts.fetch(
|
||||||
`${this.opts.baseURL}/v2/exchange-rates?currency=${currencyCode}`,
|
`${this.opts.baseURL}/v2/exchange-rates?currency=${currencyCode}`,
|
||||||
{},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// If request failed, throw an error.
|
// If request failed, throw an error.
|
||||||
@@ -163,7 +162,7 @@ export type RatesCoinbaseOptions = {
|
|||||||
/**
|
/**
|
||||||
* Optional fetch-like function (e.g. global fetch) for HTTP calls.
|
* 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.
|
// The rates payload schema we receive from Coinbase's API.
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export class RatesComposite extends BaseRates {
|
|||||||
constructor(
|
constructor(
|
||||||
private adapters: BaseRates[],
|
private adapters: BaseRates[],
|
||||||
private policy: RatesCompositePolicy = ratesAveragePolicy,
|
private policy: RatesCompositePolicy = ratesAveragePolicy,
|
||||||
private refreshIntervalMs: number = 1000,
|
private refreshIntervalMs: number = 60000,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@@ -36,9 +36,6 @@ export class RatesComposite extends BaseRates {
|
|||||||
* Start all rate adapters and setup event listeners
|
* Start all rate adapters and setup event listeners
|
||||||
*/
|
*/
|
||||||
public async start(): Promise<void> {
|
public async start(): Promise<void> {
|
||||||
// Start all adapters
|
|
||||||
await Promise.all(this.adapters.map((adapter) => adapter.start()));
|
|
||||||
|
|
||||||
// Setup event listeners for all adapters
|
// Setup event listeners for all adapters
|
||||||
for (let i = 0; i < this.adapters.length; i++) {
|
for (let i = 0; i < this.adapters.length; i++) {
|
||||||
const adapter = this.adapters[i];
|
const adapter = this.adapters[i];
|
||||||
@@ -59,6 +56,9 @@ export class RatesComposite extends BaseRates {
|
|||||||
this.unsubscribeFunctions.push(unsubscribe);
|
this.unsubscribeFunctions.push(unsubscribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start all adapters
|
||||||
|
await Promise.all(this.adapters.map((adapter) => adapter.start()));
|
||||||
|
|
||||||
// Start periodic refresh to emit combined rates
|
// Start periodic refresh to emit combined rates
|
||||||
this.startPeriodicRefresh();
|
this.startPeriodicRefresh();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user