@@ -2,11 +2,13 @@ import { syncedDocument } from 'edge-server-tools'
22import type { HttpResponse } from 'serverlet'
33import type { ExpressRequest } from 'serverlet/express'
44
5+ import { config } from '../config'
56import { ONE_MINUTE } from './constants'
67import { getRates } from './getRates'
78import { dbSettings } from './providers/couch'
89import {
910 asCrossChainMapping ,
11+ asGetRatesParams ,
1012 asIncomingGetRatesParams ,
1113 type CrossChainMapping ,
1214 type GetRatesParams ,
@@ -148,3 +150,61 @@ export const ratesV3 = async (
148150 }
149151 }
150152}
153+
154+ export const heartbeatV3 = async (
155+ request : ExpressRequest
156+ ) : Promise < HttpResponse > => {
157+ const testData = {
158+ targetFiat : 'USD' ,
159+ crypto : [
160+ {
161+ asset : {
162+ pluginId : 'bitcoin' ,
163+ tokenId : null
164+ }
165+ }
166+ ] ,
167+ fiat : [
168+ {
169+ fiatCode : 'EUR'
170+ }
171+ ]
172+ }
173+
174+ const response = await fetch (
175+ `http://${ config . httpHost } :${ config . httpPort } /v3/rates` ,
176+ {
177+ method : 'POST' ,
178+ headers : {
179+ 'Content-Type' : 'application/json'
180+ } ,
181+ body : JSON . stringify ( testData )
182+ }
183+ )
184+
185+ if ( ! response . ok ) {
186+ return {
187+ status : 500 ,
188+ headers : { 'content-type' : 'application/json' } ,
189+ body : JSON . stringify ( { error : 'Failed to fetch rates' } )
190+ }
191+ }
192+
193+ const json = await response . json ( )
194+ const data = asGetRatesParams ( json )
195+ const btcRate = data . crypto . find ( c => c . asset . pluginId === 'bitcoin' )
196+ const eurRate = data . fiat . find ( f => f . fiatCode === 'EUR' )
197+ if ( btcRate == null || eurRate == null ) {
198+ return {
199+ status : 500 ,
200+ headers : { 'content-type' : 'application/json' } ,
201+ body : JSON . stringify ( { error : 'Failed to fetch rates' } )
202+ }
203+ }
204+
205+ return {
206+ status : response . status ,
207+ headers : { 'content-type' : 'application/json' } ,
208+ body : JSON . stringify ( json )
209+ }
210+ }
0 commit comments