-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getPrices coulb be used globally. The representation is:
SimplePriceRequest
- Loading branch information
1 parent
03ab237
commit 21a0cc3
Showing
2 changed files
with
62 additions
and
49 deletions.
There are no files selected for viewing
49 changes: 0 additions & 49 deletions
49
apps/website/src/app/demos/dashboard-trade/utils/getPrices.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import axios, {AxiosResponse} from 'axios' | ||
|
||
import { | ||
CoingeckoSimplePriceRequest, | ||
CoingeckoSimplePriceResponse, | ||
} from '@/types/coingecko/simplePrices' | ||
import generateRequestParams from '@/utils/coingecko/simplePrices/generateRequestParams' | ||
|
||
class SimplePriceRequest { | ||
params: CoingeckoSimplePriceRequest | ||
|
||
constructor(params: CoingeckoSimplePriceRequest) { | ||
this.params = params | ||
} | ||
|
||
async execute(): Promise<Array<CoingeckoSimplePriceResponse>> { | ||
const options = generateRequestParams(this.params) | ||
|
||
const promise: Promise<Array<CoingeckoSimplePriceResponse>> = new Promise( | ||
(resolve, reject) => { | ||
axios | ||
.request(options) | ||
.then(function (response: AxiosResponse) { | ||
const keys = Object.keys(response.data) | ||
|
||
const coingeckoPrices: Array<CoingeckoSimplePriceResponse> = | ||
keys.map(key => { | ||
const item = response.data[key] | ||
const cryptoCurrency = key | ||
|
||
const btc = item.btc || 0 | ||
const eth = item.eth || 0 | ||
const usd = item.usd || 0 | ||
const btc_24h_change = item.btc_24h_change || 0 | ||
const eth_24h_change = item.eth_24h_change || 0 | ||
const usd_24h_change = item.usd_24h_change || 0 | ||
|
||
return { | ||
cryptoCurrency, | ||
btc: btc, | ||
usd: usd, | ||
eth: eth, | ||
btc_24h_change, | ||
eth_24h_change, | ||
usd_24h_change, | ||
} | ||
}) | ||
|
||
resolve(coingeckoPrices) | ||
}) | ||
.catch(function (error) { | ||
console.error('prices ...', error) | ||
reject(error) | ||
}) | ||
}, | ||
) | ||
|
||
return promise | ||
} | ||
} | ||
|
||
export default SimplePriceRequest |