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

Commit

Permalink
chore: Refactor onMounted hook (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzbo authored Oct 20, 2023
1 parent d373c60 commit c5c62da
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
34 changes: 17 additions & 17 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (typeof window !== 'undefined') {
}
const web3Store = useWeb3Store()
const appStore = useAppStore()
const { getNetwork, selectedNetwork, modal } = useAppStore()
const { addProviderEvents, removeProviderEvents, disconnect } =
useBrowserExtension()
const {
Expand All @@ -36,10 +36,7 @@ const setupWeb3Instances = () => {
}
// for chain interactions through RPC endpoint
web3Store.addWeb3(
PROVIDERS.RPC,
appStore.getNetwork(appStore.selectedNetwork).rpcHttp
)
web3Store.addWeb3(PROVIDERS.RPC, getNetwork(selectedNetwork).rpcHttp)
}
const setupConnectedProfile = async () => {
Expand Down Expand Up @@ -80,8 +77,8 @@ const routerBackProfileLoad = async () => {
assertAddress(toProfileAddress, 'profile')
if (toProfileAddress !== fromProfileAddress) {
await setupViewedProfile(toProfileAddress)
await setupViewedAssets(toProfileAddress)
await loadViewedProfile(toProfileAddress)
await loadViewedAssets(toProfileAddress)
}
} catch (error) {
console.error(error)
Expand Down Expand Up @@ -119,27 +116,30 @@ const setupCurrencies = async () => {
currencyList.value = await fetchCurrencies()
}
onMounted(async () => {
setupTranslations()
setupWeb3Instances()
checkConnectionExpiry()
await setupConnectedProfile()
await routerBackProfileLoad()
const setupViewedProfile = async () => {
try {
const profileAddress = useRouter().currentRoute.value.params?.profileAddress
if (profileAddress) {
if (isAddress(profileAddress)) {
await setupViewedProfile(profileAddress)
await setupViewedAssets(profileAddress)
await loadViewedProfile(profileAddress)
await loadViewedAssets(profileAddress)
} else {
navigateTo(notFoundRoute())
}
}
} catch (error) {
console.error(error)
}
}
onMounted(async () => {
setupTranslations()
setupWeb3Instances()
checkConnectionExpiry()
await setupConnectedProfile()
await setupViewedProfile()
await routerBackProfileLoad()
setStatus('isProfileLoaded', true)
Expand All @@ -154,7 +154,7 @@ onUnmounted(() => {
useHead({
bodyAttrs: {
class: computed(() => {
if (appStore.modal?.isOpen) {
if (modal?.isOpen) {
return 'overflow-hidden'
}
Expand Down
8 changes: 4 additions & 4 deletions composables/useBrowserExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const connect = async () => {
assertAddress(address, 'connection')
setItem(STORAGE_KEY.CONNECTED_ADDRESS, address)
const profile = await fetchProfile(address)
await setupViewedProfile(address)
await setupViewedAssets(address)
await loadViewedProfile(address)
await loadViewedAssets(address)
reloadConnectedProfile(profile)
setStatus('isConnected', true)
setConnectionExpiry()
Expand Down Expand Up @@ -130,8 +130,8 @@ const handleAccountsChanged = async (accounts: string[]) => {

try {
await navigateTo(profileRoute(address))
await setupViewedProfile(address)
await setupViewedAssets(address)
await loadViewedProfile(address)
await loadViewedAssets(address)
} catch (error) {
console.error(error)
}
Expand Down
2 changes: 1 addition & 1 deletion utils/setupViewedAssets.ts → utils/loadViewedAssets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const setupViewedAssets = async (profileAddress: Address) => {
export const loadViewedAssets = async (profileAddress: Address) => {
const { setStatus } = useViewedProfileStore()

try {
Expand Down
2 changes: 1 addition & 1 deletion utils/setupViewedProfile.ts → utils/loadViewedProfile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SetupViewedProfileError } from '@/shared/errors'

export const setupViewedProfile = async (profileAddress: Address) => {
export const loadViewedProfile = async (profileAddress: Address) => {
const { setStatus, setProfile } = useViewedProfileStore()

try {
Expand Down

0 comments on commit c5c62da

Please sign in to comment.