forked from InjectiveLabs/injective-helix-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.vue
More file actions
104 lines (88 loc) · 2.47 KB
/
Copy pathapp.vue
File metadata and controls
104 lines (88 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<script setup lang="ts">
import { WalletConnectStatus } from '@shared/types'
import { Status, StatusType } from '@injectivelabs/utils'
import { streamProvider } from '@/app/providers/StreamProvider'
import * as WalletTracker from '@/app/providers/mixpanel/WalletTracker'
import { InitialStatusKey } from '@/types'
const route = useRoute()
const router = useRouter()
const walletStore = useWalletStore()
const sharedGeoStore = useSharedGeoStore()
const isActiveTab = useDocumentVisibility()
const sharedSpotStore = useSharedSpotStore()
const sharedTokenStore = useSharedTokenStore()
const sharedWalletStore = useSharedWalletStore()
const sharedDerivativeStore = useSharedDerivativeStore()
const { $onError } = useNuxtApp()
const status = reactive(new Status(StatusType.Loading))
const unknownTokenStatus = reactive(new Status(StatusType.Loading))
onMounted(async () => {
if (route.query.automation === 'true') {
;(window as any).ethereum = new CustomEip1193Provider()
}
handleGoogleOAuth()
sharedTokenStore.fetchSupply().finally(() => unknownTokenStatus.setIdle())
Promise.all([
walletStore.init(),
sharedSpotStore.fetchAllMarkets(),
sharedGeoStore.fetchGeoLocation(),
sharedDerivativeStore.fetchAllMarkets(),
sharedTokenStore.fetchTokensUsdPriceMap()
])
.catch($onError)
.then(() => {
if (sharedWalletStore.isUserConnected) {
WalletTracker.trackWalletAddress(sharedWalletStore.injectiveAddress)
}
})
.finally(() => {
status.setIdle()
})
})
onWalletInitialConnected(() => {
WalletTracker.trackLogin({
wallet: sharedWalletStore.wallet,
address: sharedWalletStore.injectiveAddress
})
})
function handleGoogleOAuth() {
if (sharedWalletStore.isUserConnected) {
return
}
if (!route.hash) {
return
}
const params = new URLSearchParams(route.hash.substring(1))
const idToken = params.get('id_token')
if (!idToken) {
return
}
router.replace({ hash: '' })
sharedWalletStore
.initTurnkeyGoogle(idToken)
.catch($onError)
.finally(() => {
sharedWalletStore.walletConnectStatus = WalletConnectStatus.idle
})
}
provide(InitialStatusKey, status)
useIntervalFn(
() =>
Promise.all([
streamProvider.healthCheck(),
sharedTokenStore.fetchTokensUsdPriceMap()
]),
30 * 1000
)
watch(isActiveTab, (isActive) => {
if (!isActive) {
return
}
streamProvider.healthCheck()
})
</script>
<template>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</template>