From b6d03953b9900a320564a12e6b6d2dd8b5346761 Mon Sep 17 00:00:00 2001 From: softsimon Date: Wed, 26 Jun 2024 21:42:30 +0900 Subject: [PATCH] Show accelerator estimates on local instances --- .../src/api/acceleration/acceleration.routes.ts | 15 +++++++++++++++ .../app/components/tracker/tracker.component.ts | 2 +- .../transaction/transaction.component.ts | 6 ++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/backend/src/api/acceleration/acceleration.routes.ts b/backend/src/api/acceleration/acceleration.routes.ts index ae0c3f7a8..082d53330 100644 --- a/backend/src/api/acceleration/acceleration.routes.ts +++ b/backend/src/api/acceleration/acceleration.routes.ts @@ -14,6 +14,7 @@ class AccelerationRoutes { .get(config.MEMPOOL.API_URL_PREFIX + 'services/accelerator/accelerations/history', this.$getAcceleratorAccelerationsHistory.bind(this)) .get(config.MEMPOOL.API_URL_PREFIX + 'services/accelerator/accelerations/history/aggregated', this.$getAcceleratorAccelerationsHistoryAggregated.bind(this)) .get(config.MEMPOOL.API_URL_PREFIX + 'services/accelerator/accelerations/stats', this.$getAcceleratorAccelerationsStats.bind(this)) + .post(config.MEMPOOL.API_URL_PREFIX + 'services/accelerator/estimate', this.$getAcceleratorEstimate.bind(this)) ; } @@ -64,6 +65,20 @@ class AccelerationRoutes { res.status(500).end(); } } + + private async $getAcceleratorEstimate(req: Request, res: Response): Promise { + const url = `${config.MEMPOOL_SERVICES.API}/${req.originalUrl.replace('/api/v1/services/', '')}`; + try { + const response = await axios.post(url, req.body, { responseType: 'stream', timeout: 10000 }); + for (const key in response.headers) { + res.setHeader(key, response.headers[key]); + } + response.data.pipe(res); + } catch (e) { + logger.err(`Unable to get acceleration estimate from ${url} in $getAcceleratorEstimate(), ${e}`, this.tag); + res.status(500).end(); + } + } } export default new AccelerationRoutes(); \ No newline at end of file diff --git a/frontend/src/app/components/tracker/tracker.component.ts b/frontend/src/app/components/tracker/tracker.component.ts index 62ecc9bf0..fe42ef0dd 100644 --- a/frontend/src/app/components/tracker/tracker.component.ts +++ b/frontend/src/app/components/tracker/tracker.component.ts @@ -116,7 +116,7 @@ export class TrackerComponent implements OnInit, OnDestroy { hasEffectiveFeeRate: boolean; accelerateCtaType: 'alert' | 'button' = 'button'; - acceleratorAvailable: boolean = this.stateService.env.OFFICIAL_MEMPOOL_SPACE && this.stateService.env.ACCELERATOR && this.stateService.network === ''; + acceleratorAvailable: boolean = this.stateService.env.ACCELERATOR && this.stateService.network === ''; accelerationEligible: boolean = false; showAccelerationSummary = false; accelerationFlowCompleted = false; diff --git a/frontend/src/app/components/transaction/transaction.component.ts b/frontend/src/app/components/transaction/transaction.component.ts index 0348bf50a..570242a9a 100644 --- a/frontend/src/app/components/transaction/transaction.component.ts +++ b/frontend/src/app/components/transaction/transaction.component.ts @@ -136,7 +136,7 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { taprootEnabled: boolean; hasEffectiveFeeRate: boolean; accelerateCtaType: 'alert' | 'button' = 'button'; - acceleratorAvailable: boolean = this.stateService.env.OFFICIAL_MEMPOOL_SPACE && this.stateService.env.ACCELERATOR && this.stateService.network === ''; + acceleratorAvailable: boolean = this.stateService.env.ACCELERATOR && this.stateService.network === ''; showAccelerationSummary = false; showAccelerationDetails = false; scrollIntoAccelPreview = false; @@ -167,15 +167,13 @@ export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { ) {} ngOnInit() { - this.acceleratorAvailable = this.stateService.env.OFFICIAL_MEMPOOL_SPACE && this.stateService.env.ACCELERATOR && this.stateService.network === ''; - this.enterpriseService.page(); this.websocketService.want(['blocks', 'mempool-blocks']); this.stateService.networkChanged$.subscribe( (network) => { this.network = network; - this.acceleratorAvailable = this.stateService.env.OFFICIAL_MEMPOOL_SPACE && this.stateService.env.ACCELERATOR && this.stateService.network === ''; + this.acceleratorAvailable = this.stateService.env.ACCELERATOR && this.stateService.network === ''; } );