Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
fix: update LYX balance (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzbo authored Nov 9, 2023
1 parent d47eeef commit d554aad
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
13 changes: 2 additions & 11 deletions pages/[profileAddress]/send.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { isLoadedApp, isConnected } = storeToRefs(useAppStore())
const { setStatus, clearSend } = useSendStore()
const { showModal } = useModal()
const { formatMessage } = useIntl()
const { sendTransaction, getBalance, contract } = useWeb3(PROVIDERS.INJECTED)
const { sendTransaction, contract } = useWeb3(PROVIDERS.INJECTED)
const assetRepository = useRepo(AssetRepository)
onMounted(() => {
Expand Down Expand Up @@ -92,7 +92,7 @@ const handleSend = async () => {
} as TransactionConfig
await sendTransaction(transaction)
await updateLyxBalance()
await updateLyxBalance(connectedProfile.value?.address)
} else {
// custom token transfer
switch (asset.value?.standard) {
Expand Down Expand Up @@ -160,15 +160,6 @@ const handleSend = async () => {
})
}
}
const updateLyxBalance = async () => {
assertString(connectedProfile.value?.address)
const balance = await getBalance(connectedProfile.value.address)
useRepo(ProfileModel)
.where('address', connectedProfile.value.address)
.update({ balance })
}
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion utils/fetchLsp3Profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const fetchLsp3Profile = async (
lsp3Profile.backgroundImage &&
(await getAndConvertImage(lsp3Profile.backgroundImage, 800))

const { getBalance } = useWeb3(PROVIDERS.RPC) // TODO move balance out so it's always fetched
const { getBalance } = useWeb3(PROVIDERS.RPC)
const balance = await getBalance(profileAddress)

const profileImageId =
Expand Down
2 changes: 2 additions & 0 deletions utils/fetchProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const fetchProfile = async (profileAddress: Address) => {
const storeProfile = profileRepo.getProfileAndImages(profileAddress)

if (storeProfile) {
// refetch LYX balance for cached profile in case it has changed
await updateLyxBalance(profileAddress)
return
}

Expand Down
7 changes: 7 additions & 0 deletions utils/updateLyxBalance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const updateLyxBalance = async (profileAddress?: Address) => {
const { getBalance } = useWeb3(PROVIDERS.RPC)
assertString(profileAddress)
const balance = await getBalance(profileAddress)

useRepo(ProfileModel).where('address', profileAddress).update({ balance })
}

0 comments on commit d554aad

Please sign in to comment.