Skip to content

Commit ba8201a

Browse files
authored
fix: UI doesn't show any error if sequencer is down or unavailable (#981)
* fix: Catch function in send function is not working * Add a test file to test voting with connected wallet * Add a test file to test voting with connected wallet * v0.11.13
1 parent 092dd38 commit ba8201a

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@snapshot-labs/snapshot.js",
3-
"version": "0.11.12",
3+
"version": "0.11.13",
44
"repository": "snapshot-labs/snapshot.js",
55
"license": "MIT",
66
"main": "dist/snapshot.cjs.js",

src/sign/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default class Client {
9797
if (res.ok) return resolve(res.json());
9898
throw res;
9999
})
100-
.catch((e) => e.json().then((json) => reject(json)));
100+
.catch((e) => reject(e));
101101
});
102102
}
103103

test/test.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!-- This is a simple example of how to use snapshot.js to vote using a web3 provider -->
2+
<!-- serve -p 9000 -->
3+
<!-- Go to http://localhost:9000/test/test.html -->
4+
<script src="../dist/snapshot.min.js"></script>
5+
<script src="https://cdn.ethers.io/lib/ethers-5.6.umd.min.js" type="text/javascript">
6+
</script>
7+
8+
9+
10+
<button id="connectButton">Connect</button>
11+
<button id="voteButton">Vote</button>
12+
13+
<script>
14+
const hub = 'http://localhost:3001'; // or https://testnet.hub.snapshot.org for testnet
15+
const client = new snapshot.Client712(hub);
16+
17+
// Connect to Ethereum wallet
18+
document.getElementById("connectButton").addEventListener("click", async () => {
19+
await window.ethereum.request({ method: 'eth_requestAccounts' });
20+
console.log('Connected to wallet', await window.ethereum.request({ method: 'eth_accounts' }));
21+
});
22+
23+
// Vote using snapshot.js
24+
document.getElementById("voteButton").addEventListener("click", async () => {
25+
const web3 = new ethers.providers.Web3Provider(window.ethereum);
26+
const [account] = await web3.listAccounts();
27+
try {
28+
const receipt = await client.vote(web3, account, {
29+
space: 'yam.eth',
30+
proposal: '0x21ea31e896ec5b5a49a3653e51e787ee834aaf953263144ab936ed756f36609f',
31+
type: 'single-choice',
32+
choice: 1,
33+
reason: 'Choice 1 make lot of sense',
34+
app: 'my-app'
35+
});
36+
} catch (error) {
37+
console.log('catched an error', error);
38+
}
39+
});
40+
</script>

0 commit comments

Comments
 (0)