Skip to content

Commit

Permalink
chore: sync external contributions (#6984)
Browse files Browse the repository at this point in the history
This is a workaround for CI not triggering secrets on external PRs. In
the future we should perhaps automate this.

Features:
```
fix: Use Date.now() in case performance.now() is undefined (#6982)
It seems like `performance.now()` used in `foundation/timer.ts` isn't
supported in specific environment, such as certain browser extension
apps, web workers, embedded browsers, etc... In my case, Metamask's Snap
server app doesn't support it, causing an error in initiating a
transaction. I [patched
it](https://github.com/porco-rosso-j/aztec-snap/tree/0.41.0/patches) but
thought it'd be good to add the fix here as other developers might face
it.

<img width="590" alt="Screenshot 2024-06-08 at 20 09 39"
src="https://github.com/AztecProtocol/aztec-packages/assets/88586592/fdc8ddae-f7f9-4161-9cd4-e87357f4bed3">

This PR doesn't replace `performance.now()` but lets Timer class's
methods switch to use `Date.now()` when `peformance` is undefined.
```

Co-authored-by: porco <88586592+porco-rosso-j@users.noreply.github.com>
  • Loading branch information
ludamad and porco-rosso-j authored Jul 5, 2024
1 parent e05f6f0 commit a265b29
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions yarn-project/foundation/src/timer/timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Timer {
private start: number;

constructor() {
this.start = performance.now();
this.start = performance ? performance.now() : Date.now();
}

/**
Expand All @@ -32,7 +32,7 @@ export class Timer {
* @returns The elapsed time in milliseconds.
*/
public ms() {
return performance.now() - this.start;
return (performance ? performance.now() : Date.now()) - this.start;
}

/**
Expand Down

0 comments on commit a265b29

Please sign in to comment.