Skip to content

Commit

Permalink
Mobile ppom init fix (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri authored Nov 7, 2023
1 parent 975cac5 commit ac00265
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/ppom-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ export class PPOMController extends BaseControllerV2<

// Async initialisation of PPOM as soon as controller is constructed and not when transactions are received
// This helps to reduce the delay in validating transactions.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.#initialisePPOM();
}

Expand Down Expand Up @@ -352,6 +353,7 @@ export class PPOMController extends BaseControllerV2<
this.#providerRequests = 0;
this.#providerRequestsCount = {};

await this.#initialisePPOM();
return await this.#ppomMutex.use(async () => {
const ppom = await this.#getPPOM();
const result = await callback(ppom);
Expand All @@ -373,9 +375,9 @@ export class PPOMController extends BaseControllerV2<
* Initialisation is done as soon as controller is constructed
* or as user enables preference for blcokaid validation.
*/
#initialisePPOM() {
async #initialisePPOM() {
if (this.#securityAlertsEnabled && !this.#ppomInitialised) {
this.#ppomMutex
await this.#ppomMutex
.use(async () => {
const { ppomInit } = this.#ppomProvider;
await ppomInit('./ppom_bg.wasm');
Expand Down Expand Up @@ -482,6 +484,7 @@ export class PPOMController extends BaseControllerV2<
}
this.#securityAlertsEnabled = blockaidEnabled;
if (blockaidEnabled) {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.#initialisePPOM();
this.#checkScheduleFileDownloadForAllChains();
} else {
Expand Down Expand Up @@ -932,7 +935,6 @@ export class PPOMController extends BaseControllerV2<
async #getPPOM(): Promise<any> {
// For some reason ppom initialisation in contrructor fails for react native
// thus it is added here to prevent validation from failing.
this.#initialisePPOM();
const { chainStatus } = this.state;
const chainInfo = chainStatus[this.#chainId];
if (!chainInfo?.versionInfo?.length) {
Expand Down

0 comments on commit ac00265

Please sign in to comment.