Skip to content

Commit

Permalink
BaseScan util
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmKio committed Mar 16, 2024
1 parent 014400d commit 334ab3f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/firebase-hosting-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
REACT_APP_CHAIN_ID: 84532
REACT_APP_ASSET_SYMBOL: BASE
REACT_APP_NATIVE_ASSET_PRICE_CHAIN_ID: 8453
REACT_APP_BASESCAN_KEY: "${{ secrets.BASESCAN_KEY }}"
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/components/Profile/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "@mui/joy";
import React, { useState } from "react";
import Identicon from "react-hooks-identicons";
import fetchAccountBalance from "../../services/BaseScan";
import { useGetJarsQuery, useUpdateJarsMutation } from "../../services/api";

export default function Profile() {
Expand All @@ -37,12 +38,17 @@ export default function Profile() {
);
setFetchedBalance(fetchedBalances);
};
const baseAccountBalance = async (address) => {
const balance = await fetchAccountBalance(address);
setFetchedBalance(balance);
};

React.useEffect(() => {
if (jarsData) {
setHandle(jarsData.handle);
baseAccountBalance(jarsData.etherspotAddress);
}
fetchedBalancesAction();
// fetchedBalancesAction();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [jarsData]);

Expand Down Expand Up @@ -110,8 +116,7 @@ export default function Profile() {
fontFamily={"monospace"}
textAlign={"center"}
>
{fetchedBalance?.length &&
etherspotUtils.parseBigNumber(fetchedBalance[0].balance)}
{fetchedBalance && etherspotUtils.parseBigNumber(fetchedBalance)}
</Typography>
</Box>
)}
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/services/BaseScan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function fetchAccountBalance(address) {
return fetch(
`https://api-sepolia.basescan.org/api?module=account&action=balance&address=${address}&tag=latest&apikey=${process.env.REACT_APP_BASESCAN_KEY}`
)
.then((res) => res.json())
.then((data) => data.result);
}

0 comments on commit 334ab3f

Please sign in to comment.