Skip to content

Commit

Permalink
Merge pull request #121 from madfish-solutions/TW-1159-temple-wallet-…
Browse files Browse the repository at this point in the history
…backend-fix-exchange-rates

TW-1159 Update work with tzstats API (now called tzpro)
  • Loading branch information
lourenc authored Oct 31, 2023
2 parents 89e076c + 7a7048e commit 8313bdc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ THREE_ROUTE_API_AUTH_TOKEN=
REDIS_URL=
ADD_NOTIFICATION_USERNAME=
ADD_NOTIFICATION_PASSWORD=
TZPRO_API_KEY=
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The Express backend which helps Temple Wallet to decrease amount of requests to
| Path | Description |
| ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| /api/dapps | Provides a list of dApps with their TVL, summary TVL and amount of TEZ locked in them. |
| /api/exchange-rates/tez | Returns a single number, which is TEZ to USD exchange rate according to markets tickers from tzstats.com |
| /api/exchange-rates/tez | Returns a single number, which is TEZ to USD exchange rate according to markets tickers from TzPro API.com |
| /api/exchange-rates | Returns the exchange rates of tokens to USD based on Quipuswap and Dexter pools (for most of them), stats from TZero (only for Aspencoin) and exchange rates from Coingecko (for WRAP tokens which are still not in pools). |
| /api/moonpay-sign | Returns signed MoonPay url |
| /api/mobile-check | Returns the minimum allowed versions of Android and IOS applications. Verifies App Check token. |
Expand Down
3 changes: 2 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const EnvVars = {
THREE_ROUTE_API_AUTH_TOKEN: getEnv('THREE_ROUTE_API_AUTH_TOKEN'),
REDIS_URL: getEnv('REDIS_URL'),
ADD_NOTIFICATION_USERNAME: getEnv('ADD_NOTIFICATION_USERNAME'),
ADD_NOTIFICATION_PASSWORD: getEnv('ADD_NOTIFICATION_PASSWORD')
ADD_NOTIFICATION_PASSWORD: getEnv('ADD_NOTIFICATION_PASSWORD'),
TZPRO_API_KEY: getEnv('TZPRO_API_KEY')
};

for (const name in EnvVars) {
Expand Down
5 changes: 4 additions & 1 deletion src/utils/tezos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { tzip12 } from '@taquito/tzip12';
import { tzip16 } from '@taquito/tzip16';
import memoizee from 'memoizee';

import { EnvVars } from '../config';
import { ITicker } from '../interfaces/ticker.interface';
import fetch from './fetch';
import SingleQueryDataProvider from './SingleQueryDataProvider';
Expand Down Expand Up @@ -53,7 +54,9 @@ export const getStorage = memoizee(
);

const getTezExchangeRate = async () => {
const marketTickers = await fetch<Array<ITicker>>('https://api.tzstats.com/markets/tickers');
const marketTickers = await fetch<Array<ITicker>>(
`https://api.tzpro.io/markets/tickers?api_key=${EnvVars.TZPRO_API_KEY}`
);
const usdTickers = marketTickers.filter(e => e.quote === 'USD' && e.base === 'XTZ');
// price index: use all USD ticker last prices with equal weight
const vol = usdTickers.reduce((s, t) => s + t.volume_base, 0) || null;
Expand Down

0 comments on commit 8313bdc

Please sign in to comment.