Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
fix(time): Remove polynomial regular expression (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Sep 30, 2022
1 parent 5a6b153 commit 6f3410e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/CoinbasePro.ts
Expand Up @@ -79,7 +79,7 @@ export class CoinbasePro {
*/
if (this.clockSkew === -1) {
const time = await this.rest.time.getTime();
this.clockSkew = await this.rest.time.getClockSkew(time);
this.clockSkew = this.rest.time.getClockSkew(time);
}

return RequestSigner.signRequest(auth, setup, this.clockSkew);
Expand Down
19 changes: 0 additions & 19 deletions src/time/TimeAPI.test.ts
Expand Up @@ -35,23 +35,4 @@ describe('TimeAPI', () => {
expect(time).toEqual(expected);
});
});

describe('getClockSkew', () => {
beforeEach(() => jasmine.clock().install());

afterEach(() => jasmine.clock().uninstall());

it('handles epochs sent as string', async () => {
const mockDate = new Date(1610486424105);
jasmine.clock().mockDate(mockDate);

const mockPayload = '{"iso":"2021-01-12T21:20:24Z","epoch":1610486424.}';

const timeApi = new TimeAPI(global.REST_URL);

const clockSkew = await timeApi.getClockSkew(mockPayload);

expect(clockSkew).toBe(-0.10500001907348633);
});
});
});
6 changes: 2 additions & 4 deletions src/time/TimeAPI.ts
Expand Up @@ -31,10 +31,8 @@ export class TimeAPI {
/**
* Get the absolute difference between server time and local time.
*/
async getClockSkew(time: TimeSkew | string): Promise<number> {
/** @see https://github.com/bennycode/coinbase-pro-node/issues/354 */
const epoch = typeof time === 'string' ? parseFloat(time.match(/epoch":(.*)\./i)![1]) : time.epoch;
getClockSkew(time: TimeSkew): number {
const now = Date.now() / 1000;
return epoch - now;
return time.epoch - now;
}
}

0 comments on commit 6f3410e

Please sign in to comment.