Skip to content

Commit

Permalink
Fetch Mezo points and BTC/USD price from Acre API (#782)
Browse files Browse the repository at this point in the history
In thesis/acre-bots#49 we exposed the Mezo mats
data and BTC/USD price from the Acre API.
The data are cached on the Acre API side, so we don't need to worry
about
hitting the external endpoints rate limits from the dApp.
We don't need to worry about maintaining the Mezo API URL and API_KEY in
the dApp.
  • Loading branch information
r-czajkowski authored Oct 24, 2024
2 parents f134fc8 + c81ed2c commit a8ec584
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 72 deletions.
2 changes: 0 additions & 2 deletions dapp/.env
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ VITE_ACRE_API_ENDPOINT="http://localhost:8788/api/v1/"
VITE_GELATO_RELAY_API_KEY="htaJCy_XHj8WsE3w53WBMurfySDtjLP_TrNPPa6IPIc_" # this key should not be used on production
# Get the API key from: https://thegraph.com/studio/apikeys/.
VITE_SUBGRAPH_API_KEY=""
# Get the API key from: 1Password.
VITE_MEZO_PORTAL_API_KEY=""

# Feature flags
VITE_FEATURE_FLAG_GAMIFICATION_ENABLED="false"
Expand Down
3 changes: 0 additions & 3 deletions dapp/src/constants/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const GELATO_RELAY_API_KEY = import.meta.env.VITE_GELATO_RELAY_API_KEY

const SUBGRAPH_API_KEY = import.meta.env.VITE_SUBGRAPH_API_KEY

const MEZO_PORTAL_API_KEY = import.meta.env.VITE_MEZO_PORTAL_API_KEY

const NETWORK_TYPE = USE_TESTNET ? "testnet" : "mainnet"

const LATEST_COMMIT_HASH = import.meta.env.VITE_LATEST_COMMIT_HASH
Expand All @@ -34,7 +32,6 @@ export default {
TBTC_API_ENDPOINT,
GELATO_RELAY_API_KEY,
SUBGRAPH_API_KEY,
MEZO_PORTAL_API_KEY,
NETWORK_TYPE,
LATEST_COMMIT_HASH,
ACRE_API_ENDPOINT,
Expand Down
4 changes: 2 additions & 2 deletions dapp/src/hooks/useMats.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useQuery } from "@tanstack/react-query"
import { REFETCH_INTERVAL_IN_MILLISECONDS, queryKeysFactory } from "#/constants"
import { mezoPortalAPI } from "#/utils"
import { acreApi } from "#/utils"

const { acreKeys } = queryKeysFactory

export default function useMats() {
return useQuery({
queryKey: [...acreKeys.mats()],
queryFn: async () => mezoPortalAPI.getMats(),
queryFn: async () => acreApi.getMats(),
refetchInterval: REFETCH_INTERVAL_IN_MILLISECONDS,
})
}
14 changes: 2 additions & 12 deletions dapp/src/store/btc/btcThunk.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { createAsyncThunk } from "@reduxjs/toolkit"
import { fetchCryptoCurrencyPriceUSD } from "#/utils/exchangeApi"
import sentry from "#/sentry"
import { acreApi } from "#/utils"

export const fetchBTCPriceUSD = createAsyncThunk(
"btc/fetchBTCPriceUSD",
async () => {
try {
const priceUSD = await fetchCryptoCurrencyPriceUSD("bitcoin")
return priceUSD
} catch (error) {
sentry.captureException(error)
console.error(error)
return 0
}
},
async () => acreApi.getBtcUsdPrice(),
)
2 changes: 0 additions & 2 deletions dapp/src/types/coingecko.ts

This file was deleted.

1 change: 0 additions & 1 deletion dapp/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export * from "./callback"
export * from "./chain"
export * from "./action-flow"
export * from "./activity"
export * from "./coingecko"
export * from "./time"
export * from "./core"
export * from "./fee"
Expand Down
18 changes: 18 additions & 0 deletions dapp/src/utils/acreApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,29 @@ const claimPoints = async (address: string) => {
}
}

async function getMats() {
const response = await axios.get<{ totalMats: number; dailyMats: number }>(
"mezo/points",
)

return {
totalMats: response.data.totalMats,
dailyMats: response.data.dailyMats,
}
}

async function getBtcUsdPrice(): Promise<number> {
const response = await axios.get<{ btcUsdPrice: number }>("currency/btc")
return response.data.btcUsdPrice
}

export default {
createSession,
getSession,
deleteSession,
getPointsData,
getPointsDataByUser,
claimPoints,
getMats,
getBtcUsdPrice,
}
20 changes: 0 additions & 20 deletions dapp/src/utils/exchangeApi.ts

This file was deleted.

2 changes: 0 additions & 2 deletions dapp/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export * from "./chain"
export * from "./text"
export * from "./time"
export * from "./promise"
export * from "./exchangeApi"
export * from "./verifyDepositAddress"
export * from "./json"
export * from "./activities"
Expand All @@ -15,6 +14,5 @@ export { default as eip1193 } from "./eip1193"
export { default as orangeKit } from "./orangeKit"
export { default as userAgent } from "./userAgent"
export { default as referralProgram } from "./referralProgram"
export { default as mezoPortalAPI } from "./mezoPortalApi"
export { default as acreApi } from "./acreApi"
export { default as router } from "./router"
27 changes: 0 additions & 27 deletions dapp/src/utils/mezoPortalApi.ts

This file was deleted.

1 change: 0 additions & 1 deletion dapp/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ interface ImportMetaEnv {
readonly VITE_FEATURE_FLAG_ACRE_POINTS_ENABLED: string
readonly VITE_FEATURE_FLAG_TVL_ENABLED: string
readonly VITE_SUBGRAPH_API_KEY: string
readonly VITE_MEZO_PORTAL_API_KEY: string
readonly VITE_LATEST_COMMIT_HASH: string
readonly VITE_ACRE_API_ENDPOINT: string
}
Expand Down

0 comments on commit a8ec584

Please sign in to comment.