Skip to content

Commit 8ed4d78

Browse files
committed
feat(fe) updating to bandchain 2
1 parent 1e815e8 commit 8ed4d78

File tree

7 files changed

+111
-218
lines changed

7 files changed

+111
-218
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"dependencies": {
66
"@babel/helper-call-delegate": "^7.12.1",
7-
"@bandprotocol/bandchain.js": "1.1.6",
7+
"@bandprotocol/bandchain.js": "2.0.1",
88
"@material-ui/core": "^4.11.3",
99
"@material-ui/icons": "^4.11.2",
1010
"@material-ui/lab": "^4.0.0-alpha.57",

src/constants/environmentVariables.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const NETWORK = process.env.REACT_APP_NETWORK || "testnet";
22
const INFURA_ID = process.env.REACT_APP_INFURA_ID || "";
33

4-
const BANDCHAIN_ENDPOINT =
5-
process.env.REACT_APP_BANDCHAIN_ENDPOINT || "https://api-gm-lb.bandchain.org";
64
const GAS_FEE_ENDPOINT =
75
process.env.REACT_APP_GAS_FEE_ENDPOINT ||
86
"https://api.anyblock.tools/ethereum/latest-minimum-gasprice/?pretty";
@@ -36,7 +34,6 @@ export const env = {
3634
DEV,
3735
NETWORK,
3836
INFURA_ID,
39-
BANDCHAIN_ENDPOINT,
4037
GAS_FEE_ENDPOINT,
4138
XSTATE_DEVTOOLS,
4239
BSC_MM_ENABLED,

src/features/marketData/marketDataHooks.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
} from "../ui/uiSlice";
1010
import { setExchangeRates, setGasPrices } from "./marketDataSlice";
1111
import {
12-
BandchainExchangeRateEntry,
12+
BandchainReferenceData,
1313
bandchainReferencePairs,
14-
CoingeckoExchangeRateEntry,
14+
CoingeckoReferenceData,
1515
coingeckoSymbols,
1616
fetchMarketDataGasPrices,
1717
mapBandchainToExchangeData,
@@ -25,8 +25,8 @@ export const useExchangeRates = () => {
2525

2626
const fetchMarketDataRates = useCallback(async () => {
2727
const bandchain = await getBandchain()
28-
.getReferenceData(bandchainReferencePairs)
29-
.then((data: Array<BandchainExchangeRateEntry>) => {
28+
.getReferenceData(bandchainReferencePairs, 3, 4)
29+
.then((data: Array<BandchainReferenceData>) => {
3030
dispatch(
3131
setSystemMonitorStatus({
3232
type: SystemType.Bandchain,
@@ -52,7 +52,7 @@ export const useExchangeRates = () => {
5252
`/coins/markets?vs_currency=usd&ids=${coingeckoSymbols.join(",")}`
5353
)
5454
.then((response) => response.json())
55-
.then((data: Array<CoingeckoExchangeRateEntry>) => {
55+
.then((data: Array<CoingeckoReferenceData>) => {
5656
dispatch(
5757
setSystemMonitorStatus({
5858
type: SystemType.Coingecko,

src/features/marketData/marketDataUtils.ts

+5-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { ReferenceData } from "@bandprotocol/bandchain.js/lib/data";
12
import { env } from "../../constants/environmentVariables";
2-
import { getBandchain } from "../../services/bandchain";
33
import { uniqueArray } from "../../utils/arrays";
44
import {
55
BridgeChain,
@@ -36,22 +36,15 @@ export const coingeckoSymbols = Object.values(currenciesConfig)
3636
.filter((entry) => Boolean(entry.coingeckoSymbol))
3737
.map((entry) => entry.coingeckoSymbol);
3838

39-
export type BandchainExchangeRateEntry = {
40-
pair: string;
41-
rate: number;
42-
updated: {
43-
base: number;
44-
quote: number;
45-
};
46-
};
39+
export type BandchainReferenceData = ReferenceData;
4740

48-
export type CoingeckoExchangeRateEntry = {
41+
export type CoingeckoReferenceData = {
4942
symbol: string;
5043
current_price: number;
5144
};
5245

5346
export const mapBandchainToExchangeData = (
54-
referenceData: Array<BandchainExchangeRateEntry>
47+
referenceData: Array<BandchainReferenceData>
5548
) => {
5649
return referenceData.map((entry: any) => {
5750
const [base, quote] = entry.pair.split("/");
@@ -64,7 +57,7 @@ export const mapBandchainToExchangeData = (
6457
};
6558

6659
export const mapCoingeckoToExchangeData = (
67-
entries: Array<CoingeckoExchangeRateEntry>
60+
entries: Array<CoingeckoReferenceData>
6861
) => {
6962
return entries.map((entry: any) => ({
7063
pair: getPair(entry.symbol, "USD"),
@@ -82,29 +75,6 @@ export type GasPrice = {
8275
standard: number;
8376
};
8477

85-
export const fetchMarketDataRates = async () => {
86-
const bandchain = await getBandchain()
87-
.getReferenceData(bandchainReferencePairs)
88-
.then(mapBandchainToExchangeData)
89-
.catch((error: any) => {
90-
console.error(error);
91-
return [];
92-
});
93-
94-
const coingecko = await fetch(
95-
"https://api.coingecko.com/api/v3" +
96-
`/coins/markets?vs_currency=usd&ids=${coingeckoSymbols.join(",")}`
97-
)
98-
.then((response) => response.json())
99-
.then(mapCoingeckoToExchangeData)
100-
.catch((error: any) => {
101-
console.error(error);
102-
return [];
103-
});
104-
105-
return [...bandchain, ...coingecko];
106-
};
107-
10878
export const findExchangeRate = (
10979
exchangeRates: Array<ExchangeRate>,
11080
base: BridgeCurrency,

src/lib/declarations/bandchain.d.ts

-1
This file was deleted.

src/services/bandchain.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import BandChain from '@bandprotocol/bandchain.js'
2-
import { env } from '../constants/environmentVariables'
1+
import Client from "@bandprotocol/bandchain.js/lib/client";
32

4-
let bandchainInstance: typeof BandChain | null = null;
3+
let bandchainInstance: any | null = null;
4+
5+
// BandChain's Proof-of-Authority REST endpoint
6+
const endpoint = "https://laozi-testnet4.bandchain.org/grpc-web";
57

68
export const getBandchain = () => {
79
if (bandchainInstance === null) {
8-
bandchainInstance = new BandChain(env.BANDCHAIN_ENDPOINT);
10+
bandchainInstance = new Client(endpoint);
911
}
1012
return bandchainInstance;
1113
};

0 commit comments

Comments
 (0)