From 743c7e8bfb6f12e3b543ac5a2231383cf1d3b73d Mon Sep 17 00:00:00 2001 From: softsimon Date: Sun, 21 Jul 2024 22:54:58 +0800 Subject: [PATCH] Fix crypto lib call crash with custom function --- .../accelerate-checkout.component.ts | 4 ++-- frontend/src/app/shared/common.utils.ts | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/components/accelerate-checkout/accelerate-checkout.component.ts b/frontend/src/app/components/accelerate-checkout/accelerate-checkout.component.ts index 49b12bbee..e5e44d2d6 100644 --- a/frontend/src/app/components/accelerate-checkout/accelerate-checkout.component.ts +++ b/frontend/src/app/components/accelerate-checkout/accelerate-checkout.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit, OnDestroy, Output, EventEmitter, Input, ChangeDetectorRef, SimpleChanges, HostListener } from '@angular/core'; import { Subscription, tap, of, catchError, Observable, switchMap } from 'rxjs'; import { ServicesApiServices } from '../../services/services-api.service'; -import { nextRoundNumber } from '../../shared/common.utils'; +import { nextRoundNumber, simpleRandomUUID } from '../../shared/common.utils'; import { StateService } from '../../services/state.service'; import { AudioService } from '../../services/audio.service'; import { ETA, EtaService } from '../../services/eta.service'; @@ -130,7 +130,7 @@ export class AccelerateCheckout implements OnInit, OnDestroy { private authService: AuthServiceMempool, private enterpriseService: EnterpriseService, ) { - this.accelerationUUID = window.crypto.randomUUID(); + this.accelerationUUID = simpleRandomUUID(); } ngOnInit() { diff --git a/frontend/src/app/shared/common.utils.ts b/frontend/src/app/shared/common.utils.ts index 28e510e14..3e2a2e749 100644 --- a/frontend/src/app/shared/common.utils.ts +++ b/frontend/src/app/shared/common.utils.ts @@ -181,4 +181,17 @@ export function uncompressDeltaChange(delta: MempoolBlockDeltaCompressed): Mempo acc: !!tx[3], })) }; -} \ No newline at end of file +} + +export function simpleRandomUUID(): string { + const hexDigits = '0123456789abcdef'; + const uuidLengths = [8, 4, 4, 4, 12]; + let uuid = ''; + for (const length of uuidLengths) { + for (let i = 0; i < length; i++) { + uuid += hexDigits[Math.floor(Math.random() * 16)]; + } + uuid += '-'; + } + return uuid.slice(0, -1); +}