From 614432426abd3472fafabb599f2573fef8e82a90 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Tue, 9 Jul 2024 12:16:01 +0000 Subject: [PATCH] call services api directly, make endpoint configurable --- docker/frontend/entrypoint.sh | 2 + frontend/mempool-frontend-config.sample.json | 3 +- .../src/app/services/services-api.service.ts | 41 +++++++++---------- frontend/src/app/services/state.service.ts | 2 + 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/docker/frontend/entrypoint.sh b/docker/frontend/entrypoint.sh index 5b072ba8d..dc0fa6f7a 100644 --- a/docker/frontend/entrypoint.sh +++ b/docker/frontend/entrypoint.sh @@ -40,6 +40,7 @@ __MAINNET_BLOCK_AUDIT_START_HEIGHT__=${MAINNET_BLOCK_AUDIT_START_HEIGHT:=0} __TESTNET_BLOCK_AUDIT_START_HEIGHT__=${TESTNET_BLOCK_AUDIT_START_HEIGHT:=0} __SIGNET_BLOCK_AUDIT_START_HEIGHT__=${SIGNET_BLOCK_AUDIT_START_HEIGHT:=0} __ACCELERATOR__=${ACCELERATOR:=false} +__SERVICES_API__=${SERVICES_API:=false} __PUBLIC_ACCELERATIONS__=${PUBLIC_ACCELERATIONS:=false} __HISTORICAL_PRICE__=${HISTORICAL_PRICE:=true} __ADDITIONAL_CURRENCIES__=${ADDITIONAL_CURRENCIES:=false} @@ -69,6 +70,7 @@ export __MAINNET_BLOCK_AUDIT_START_HEIGHT__ export __TESTNET_BLOCK_AUDIT_START_HEIGHT__ export __SIGNET_BLOCK_AUDIT_START_HEIGHT__ export __ACCELERATOR__ +export __SERVICES_API__ export __PUBLIC_ACCELERATIONS__ export __HISTORICAL_PRICE__ export __ADDITIONAL_CURRENCIES__ diff --git a/frontend/mempool-frontend-config.sample.json b/frontend/mempool-frontend-config.sample.json index cafedd63f..38a671edf 100644 --- a/frontend/mempool-frontend-config.sample.json +++ b/frontend/mempool-frontend-config.sample.json @@ -25,5 +25,6 @@ "HISTORICAL_PRICE": true, "ADDITIONAL_CURRENCIES": false, "ACCELERATOR": false, - "PUBLIC_ACCELERATIONS": false + "PUBLIC_ACCELERATIONS": false, + "SERVICES_API": "https://mempool.space/api/v1/services" } diff --git a/frontend/src/app/services/services-api.service.ts b/frontend/src/app/services/services-api.service.ts index 07e72e0b6..ca5f0eefd 100644 --- a/frontend/src/app/services/services-api.service.ts +++ b/frontend/src/app/services/services-api.service.ts @@ -25,9 +25,6 @@ export interface IUser { ogRank: number | null; } -// Todo - move to config.json -const SERVICES_API_PREFIX = `/api/v1/services`; - @Injectable({ providedIn: 'root' }) @@ -98,7 +95,7 @@ export class ServicesApiServices { return of(null); } - return this.httpClient.get(`${SERVICES_API_PREFIX}/account`); + return this.httpClient.get(`${this.stateService.env.SERVICES_API}/account`); } getUserMenuGroups$(): Observable { @@ -107,7 +104,7 @@ export class ServicesApiServices { return of(null); } - return this.httpClient.get(`${SERVICES_API_PREFIX}/account/menu`); + return this.httpClient.get(`${this.stateService.env.SERVICES_API}/account/menu`); } logout$(): Observable { @@ -117,59 +114,59 @@ export class ServicesApiServices { } localStorage.removeItem('auth'); - return this.httpClient.post(`${SERVICES_API_PREFIX}/auth/logout`, {}); + return this.httpClient.post(`${this.stateService.env.SERVICES_API}/auth/logout`, {}); } getJWT$() { - return this.httpClient.get(`${SERVICES_API_PREFIX}/auth/getJWT`); + return this.httpClient.get(`${this.stateService.env.SERVICES_API}/auth/getJWT`); } getServicesBackendInfo$(): Observable { - return this.httpClient.get(`${SERVICES_API_PREFIX}/version`); + return this.httpClient.get(`${this.stateService.env.SERVICES_API}/version`); } estimate$(txInput: string) { - return this.httpClient.post(`${SERVICES_API_PREFIX}/accelerator/estimate`, { txInput: txInput }, { observe: 'response' }); + return this.httpClient.post(`${this.stateService.env.SERVICES_API}/accelerator/estimate`, { txInput: txInput }, { observe: 'response' }); } accelerate$(txInput: string, userBid: number, accelerationUUID: string) { - return this.httpClient.post(`${SERVICES_API_PREFIX}/accelerator/accelerate`, { txInput: txInput, userBid: userBid, accelerationUUID: accelerationUUID }); + return this.httpClient.post(`${this.stateService.env.SERVICES_API}/accelerator/accelerate`, { txInput: txInput, userBid: userBid, accelerationUUID: accelerationUUID }); } accelerateWithCashApp$(txInput: string, token: string, cashtag: string, referenceId: string, accelerationUUID: string) { - return this.httpClient.post(`${SERVICES_API_PREFIX}/accelerator/accelerate/cashapp`, { txInput: txInput, token: token, cashtag: cashtag, referenceId: referenceId, accelerationUUID: accelerationUUID }); + return this.httpClient.post(`${this.stateService.env.SERVICES_API}/accelerator/accelerate/cashapp`, { txInput: txInput, token: token, cashtag: cashtag, referenceId: referenceId, accelerationUUID: accelerationUUID }); } getAccelerations$(): Observable { - return this.httpClient.get(`${SERVICES_API_PREFIX}/accelerator/accelerations`); + return this.httpClient.get(`${this.stateService.env.SERVICES_API}/accelerator/accelerations`); } getAggregatedAccelerationHistory$(params: AccelerationHistoryParams): Observable { - return this.httpClient.get(`${SERVICES_API_PREFIX}/accelerator/accelerations/history/aggregated`, { params: { ...params }, observe: 'response' }); + return this.httpClient.get(`${this.stateService.env.SERVICES_API}/accelerator/accelerations/history/aggregated`, { params: { ...params }, observe: 'response' }); } getAccelerationHistory$(params: AccelerationHistoryParams): Observable { - return this.httpClient.get(`${SERVICES_API_PREFIX}/accelerator/accelerations/history`, { params: { ...params } }); + return this.httpClient.get(`${this.stateService.env.SERVICES_API}/accelerator/accelerations/history`, { params: { ...params } }); } getAccelerationHistoryObserveResponse$(params: AccelerationHistoryParams): Observable { - return this.httpClient.get(`${SERVICES_API_PREFIX}/accelerator/accelerations/history`, { params: { ...params }, observe: 'response'}); + return this.httpClient.get(`${this.stateService.env.SERVICES_API}/accelerator/accelerations/history`, { params: { ...params }, observe: 'response'}); } getAccelerationStats$(params: AccelerationHistoryParams): Observable { - return this.httpClient.get(`${SERVICES_API_PREFIX}/accelerator/accelerations/stats`, { params: { ...params } }); + return this.httpClient.get(`${this.stateService.env.SERVICES_API}/accelerator/accelerations/stats`, { params: { ...params } }); } setupSquare$(): Observable<{squareAppId: string, squareLocationId: string}> { - return this.httpClient.get<{squareAppId: string, squareLocationId: string}>(`${SERVICES_API_PREFIX}/square/setup`); + return this.httpClient.get<{squareAppId: string, squareLocationId: string}>(`${this.stateService.env.SERVICES_API}/square/setup`); } getFaucetStatus$() { - return this.httpClient.get<{ address?: string, min: number, max: number, code: 'ok' | 'faucet_not_available' | 'faucet_maximum_reached' | 'faucet_too_soon'}>(`${SERVICES_API_PREFIX}/testnet4/faucet/status`, { responseType: 'json' }); + return this.httpClient.get<{ address?: string, min: number, max: number, code: 'ok' | 'faucet_not_available' | 'faucet_maximum_reached' | 'faucet_too_soon'}>(`${this.stateService.env.SERVICES_API}/testnet4/faucet/status`, { responseType: 'json' }); } requestTestnet4Coins$(address: string, sats: number) { - return this.httpClient.get<{txid: string}>(`${SERVICES_API_PREFIX}/testnet4/faucet/request?address=${address}&sats=${sats}`, { responseType: 'json' }); + return this.httpClient.get<{txid: string}>(`${this.stateService.env.SERVICES_API}/testnet4/faucet/request?address=${address}&sats=${sats}`, { responseType: 'json' }); } generateBTCPayAcceleratorInvoice$(txid: string, sats: number): Observable { @@ -177,14 +174,14 @@ export class ServicesApiServices { product: txid, amount: sats, }; - return this.httpClient.post(`${SERVICES_API_PREFIX}/payments/bitcoin`, params); + return this.httpClient.post(`${this.stateService.env.SERVICES_API}/payments/bitcoin`, params); } retreiveInvoice$(invoiceId: string): Observable { - return this.httpClient.get(`${SERVICES_API_PREFIX}/payments/bitcoin/invoice?id=${invoiceId}`); + return this.httpClient.get(`${this.stateService.env.SERVICES_API}/payments/bitcoin/invoice?id=${invoiceId}`); } getPaymentStatus$(orderId: string): Observable { - return this.httpClient.get(`${SERVICES_API_PREFIX}/payments/bitcoin/check?order_id=${orderId}`); + return this.httpClient.get(`${this.stateService.env.SERVICES_API}/payments/bitcoin/check?order_id=${orderId}`); } } diff --git a/frontend/src/app/services/state.service.ts b/frontend/src/app/services/state.service.ts index 860ff15df..ef13ea07d 100644 --- a/frontend/src/app/services/state.service.ts +++ b/frontend/src/app/services/state.service.ts @@ -75,6 +75,7 @@ export interface Env { ADDITIONAL_CURRENCIES: boolean; GIT_COMMIT_HASH_MEMPOOL_SPACE?: string; PACKAGE_JSON_VERSION_MEMPOOL_SPACE?: string; + SERVICES_API?: string; customize?: Customization; } @@ -109,6 +110,7 @@ const defaultEnv: Env = { 'ACCELERATOR': false, 'PUBLIC_ACCELERATIONS': false, 'ADDITIONAL_CURRENCIES': false, + 'SERVICES_API': 'https://mempool.space/api/v1/services', }; @Injectable({