Skip to content

Commit c842256

Browse files
authored
Improve wallet connection error handling and UI updates
1 parent 7bf2aa5 commit c842256

1 file changed

Lines changed: 54 additions & 48 deletions

File tree

js/wallet.js

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ async function connectWallet() {
4646

4747
console.error(error);
4848

49+
alert(
50+
"Gagal menghubungkan wallet"
51+
);
52+
4953
}
5054

5155
}
@@ -76,47 +80,55 @@ async function switchToEvoz() {
7680

7781
if (error.code === 4902) {
7882

79-
await window.ethereum.request({
83+
try {
84+
85+
await window.ethereum.request({
86+
87+
method:
88+
"wallet_addEthereumChain",
89+
90+
params: [
91+
92+
{
8093

81-
method:
82-
"wallet_addEthereumChain",
94+
chainId:
95+
chainHex,
8396

84-
params: [
97+
chainName:
98+
CONFIG.CHAIN_NAME,
8599

86-
{
100+
nativeCurrency: {
87101

88-
chainId:
89-
chainHex,
102+
name:
103+
CONFIG.CURRENCY_SYMBOL,
90104

91-
chainName:
92-
CONFIG.CHAIN_NAME,
105+
symbol:
106+
CONFIG.CURRENCY_SYMBOL,
93107

94-
nativeCurrency: {
108+
decimals:
109+
18
95110

96-
name:
97-
CONFIG.CURRENCY_SYMBOL,
111+
},
98112

99-
symbol:
100-
CONFIG.CURRENCY_SYMBOL,
113+
rpcUrls: [
114+
CONFIG.RPC_URL
115+
],
101116

102-
decimals:
103-
18
117+
blockExplorerUrls: [
118+
CONFIG.EXPLORER_URL
119+
]
104120

105-
},
121+
}
106122

107-
rpcUrls: [
108-
CONFIG.RPC_URL
109-
],
123+
]
110124

111-
blockExplorerUrls: [
112-
CONFIG.EXPLORER_URL
113-
]
125+
});
114126

115-
}
127+
} catch (addError) {
116128

117-
]
129+
console.error(addError);
118130

119-
});
131+
}
120132

121133
}
122134

@@ -138,17 +150,23 @@ async function updateWalletInfo() {
138150
const accounts =
139151
await provider.listAccounts();
140152

141-
if (accounts.length === 0) {
142-
153+
const connectBtn =
143154
document.getElementById(
144155
"connectBtn"
145-
).innerText =
146-
"Connect Wallet";
156+
);
147157

158+
const networkDiv =
148159
document.getElementById(
149-
"walletAddress"
150-
).innerText =
151-
"Supported by EVOZX";
160+
"networkStatus"
161+
);
162+
163+
if (accounts.length === 0) {
164+
165+
connectBtn.innerText =
166+
"Connect Wallet";
167+
168+
networkDiv.innerText =
169+
"⚪ Wallet Not Connected";
152170

153171
return;
154172

@@ -160,18 +178,11 @@ async function updateWalletInfo() {
160178
signer =
161179
provider.getSigner();
162180

163-
document.getElementById(
164-
"connectBtn"
165-
).innerText =
181+
connectBtn.innerText =
166182
shortenAddress(
167183
currentAccount
168184
);
169185

170-
document.getElementById(
171-
"walletAddress"
172-
).innerText =
173-
"Supported by EVOZX";
174-
175186
const chainId =
176187
await window.ethereum.request({
177188

@@ -180,23 +191,18 @@ async function updateWalletInfo() {
180191

181192
});
182193

183-
const networkDiv =
184-
document.getElementById(
185-
"networkStatus"
186-
);
187-
188194
if (
189195
parseInt(chainId, 16) ===
190196
CONFIG.CHAIN_ID
191197
) {
192198

193199
networkDiv.innerText =
194-
"Network: EVOZ Mainnet";
200+
"🟢 EVOZ Mainnet";
195201

196202
} else {
197203

198204
networkDiv.innerText =
199-
"Network: Wrong Network";
205+
"🔴 Wrong Network";
200206

201207
}
202208

0 commit comments

Comments
 (0)