1
1
<script setup>
2
2
/** UI */
3
3
import Button from " @/components/ui/Button.vue"
4
- import Spinner from " @/components/ui/Spinner.vue"
5
- import Tooltip from " @/components/ui/Tooltip.vue"
6
- import { Dropdown , DropdownItem , DropdownDivider } from " @/components/ui/Dropdown"
4
+ import { Dropdown , DropdownTitle , DropdownItem , DropdownDivider } from " @/components/ui/Dropdown"
7
5
8
6
/** Services */
9
7
import amp from " @/services/amp"
10
- import { suggestChain , getAccounts , disconnect } from " @ /services/keplr "
8
+ import { disconnect } from " ~ /services/wallet "
11
9
import { arabica , mocha , mainnet } from " @/services/chains"
12
10
13
- /** API */
14
- import { fetchAddressByHash } from " @/services/api/address"
15
-
16
11
/** Store */
17
12
import { useAppStore } from " @/store/app"
18
13
import { useModalsStore } from " @/store/modals"
@@ -23,14 +18,13 @@ const notificationsStore = useNotificationsStore()
23
18
24
19
const router = useRouter ()
25
20
26
- const isWalletAvailable = ref (false )
27
21
const isFetchingAccounts = ref (false )
28
22
29
23
const { hostname } = useRequestURL ()
30
24
31
25
switch (hostname) {
32
26
case " celenium.io" :
33
- // case "dev.celenium.io":
27
+ // case "dev.celenium.io":
34
28
appStore .network = mainnet
35
29
break
36
30
@@ -44,58 +38,10 @@ switch (hostname) {
44
38
default :
45
39
appStore .network = arabica
46
40
break
47
-
48
- }
49
-
50
- const getBalance = async () => {
51
- const key = await window .keplr .getKey (appStore .network .chainId )
52
-
53
- if (key) {
54
- const { data } = await fetchAddressByHash (key .bech32Address )
55
-
56
- if (data .value ? .balance ) {
57
- appStore .balance = parseFloat (data .value .balance .spendable / 1_000_000 ) || 0
58
- }
59
- }
60
41
}
61
42
62
- onMounted (async () => {
63
- isWalletAvailable .value = !! window .keplr
64
- })
65
-
66
43
const handleConnect = async () => {
67
- try {
68
- await suggestChain (appStore .network )
69
-
70
- isFetchingAccounts .value = true
71
-
72
- const accounts = await getAccounts (appStore .network )
73
- if (accounts .length ) {
74
- appStore .address = accounts[0 ].address
75
- }
76
-
77
- getBalance ()
78
-
79
- isFetchingAccounts .value = false
80
-
81
- amp .log (" connect" )
82
- } catch (error) {
83
- amp .log (" rejectConnect" )
84
-
85
- switch (error .message ) {
86
- case " Request rejected" :
87
- notificationsStore .create ({
88
- notification: {
89
- type: " info" ,
90
- icon: " close" ,
91
- title: " Request rejected" ,
92
- description: " You canceled the Keplr wallet request" ,
93
- autoDestroy: true ,
94
- },
95
- })
96
- break
97
- }
98
- }
44
+ modalsStore .open (" connect" )
99
45
}
100
46
101
47
const handleCopy = (target ) => {
@@ -111,6 +57,10 @@ const handleCopy = (target) => {
111
57
})
112
58
}
113
59
60
+ const handleChangeWallet = () => {
61
+ modalsStore .open (" connect" )
62
+ }
63
+
114
64
const handleDisconnect = () => {
115
65
disconnect ()
116
66
@@ -131,32 +81,7 @@ const handleDisconnect = () => {
131
81
</script >
132
82
133
83
<template >
134
- < Tooltip v- if = " isFetchingAccounts" position= " end" >
135
- < Button type= " secondary" size= " small" disabled>
136
- < Spinner size= " 14" / >
137
- Fetching
138
- < / Button>
139
-
140
- < template #content>
141
- < Flex direction= " column" align= " end" gap= " 6" >
142
- < Text > Receiving your accounts < / Text >
143
- < Text color= " tertiary" height= " 120" align= " right" style= " max-width: 200px" >
144
- It' s stuck? Try disabling the connection through your wallet and refresh the page
145
- </Text>
146
- <Text color="tertiary" height="120" align="right" style="max-width: 200px">
147
- Sometimes the wallet pop-up may hide behind the browser window
148
- </Text>
149
- </Flex>
150
- </template>
151
- </Tooltip>
152
-
153
- <Tooltip v-else-if="!isWalletAvailable" position="end">
154
- <Button type="white" size="mini" disabled> Connect </Button>
155
-
156
- <template #content> Install Keplr Wallet before connection </template>
157
- </Tooltip>
158
-
159
- <Button v-else-if="!appStore.address" @click="handleConnect" type="white" size="mini"> Connect </Button>
84
+ <Button v-if =" !appStore.address" @click =" handleConnect" type =" white" size =" mini" > Connect </Button >
160
85
161
86
<Dropdown v-else >
162
87
<Button type =" secondary" size =" mini" >
@@ -165,6 +90,7 @@ const handleDisconnect = () => {
165
90
</Button >
166
91
167
92
<template #popup >
93
+ <DropdownTitle style =" text-transform : capitalize " >{{ appStore.wallet }} Wallet</DropdownTitle >
168
94
<DropdownItem @click =" modalsStore.open('send')" >Send TIA</DropdownItem >
169
95
<DropdownItem @click =" modalsStore.open('pfb')" >Submit Blob</DropdownItem >
170
96
<DropdownDivider />
@@ -178,6 +104,7 @@ const handleDisconnect = () => {
178
104
<Text >Copy address</Text >
179
105
</DropdownItem >
180
106
<DropdownDivider />
107
+ <DropdownItem @click =" handleChangeWallet" >Change wallet</DropdownItem >
181
108
<DropdownItem @click =" handleDisconnect" >Disconnect</DropdownItem >
182
109
</template >
183
110
</Dropdown >
0 commit comments