Skip to content

Commit

Permalink
Use eth Address to fetch acre points data
Browse files Browse the repository at this point in the history
  • Loading branch information
kkosiorowska committed Sep 17, 2024
1 parent ccf775b commit 62b8f76
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
10 changes: 5 additions & 5 deletions dapp/src/hooks/useAcrePoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ type UseAcrePointsReturnType = {
}

export default function useAcrePoints(): UseAcrePointsReturnType {
const { address = "" } = useWallet()
const { address = "", ethAddress = "" } = useWallet()

const userPointsDataQuery = useQuery({
queryKey: [...userKeys.pointsData(), address],
enabled: !!address,
queryFn: async () => acreApi.getPointsDataByUser(address),
queryKey: [...userKeys.pointsData(), ethAddress],
enabled: !!ethAddress,
queryFn: async () => acreApi.getPointsDataByUser(ethAddress),
})

const pointsDataQuery = useQuery({
Expand All @@ -37,7 +37,7 @@ export default function useAcrePoints(): UseAcrePointsReturnType {

const { data } = userPointsDataQuery
const totalBalance = bigIntToUserAmount(data?.claimed ?? 0n, 0)
const claimableBalance = bigIntToUserAmount(data?.claimed ?? 0n, 0)
const claimableBalance = bigIntToUserAmount(data?.unclaimed ?? 0n, 0)

return {
totalBalance,
Expand Down
16 changes: 15 additions & 1 deletion dapp/src/hooks/useWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const { typeConversionToConnector, typeConversionToOrangeKitConnector } =
type UseWalletReturn = {
isConnected: boolean
address?: string
ethAddress?: string
balance?: bigint
status: Status
onConnect: (
Expand All @@ -41,6 +42,7 @@ export function useWallet(): UseWalletReturn {
const resetWalletState = useResetWalletState()

const [address, setAddress] = useState<string | undefined>(undefined)
const [ethAddress, setEthAddress] = useState<string | undefined>(undefined)

// `isConnected` is variable derived from `status` but does not guarantee us a set `address`.
// When `status` is 'connected' properties like `address` are guaranteed to be defined.
Expand Down Expand Up @@ -89,10 +91,13 @@ export function useWallet(): UseWalletReturn {
const fetchBitcoinAddress = async () => {
if (connector) {
const btcAddress = await connector.getBitcoinAddress()
const accounts = await connector.getAccounts()

setAddress(btcAddress)
setEthAddress(accounts[0])
} else {
setAddress(undefined)
setEthAddress(undefined)
}
}

Expand All @@ -103,11 +108,20 @@ export function useWallet(): UseWalletReturn {
() => ({
isConnected,
address,
ethAddress,
balance,
status,
onConnect,
onDisconnect,
}),
[address, balance, isConnected, onConnect, onDisconnect, status],
[
address,
balance,
ethAddress,
isConnected,
onConnect,
onDisconnect,
status,
],
)
}

0 comments on commit 62b8f76

Please sign in to comment.