@samudai_xyz/web3-sdk
Version:
## All in one web3 integrations for Samudai
66 lines (65 loc) • 2.3 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Snapshot = void 0;
const snapshot_js_1 = __importDefault(require("@snapshot-labs/snapshot.js"));
const snapshotQueries_1 = require("../lib/snapshotQueries");
class Snapshot {
//private hub = 'https://hub.snapshot.org'
constructor(spaceId) {
this.queries = new snapshotQueries_1.SnapshotQueries();
this.getSpace = async () => {
try {
const result = await this.queries.getSpace(this.spaceId);
return result;
}
catch (err) {
throw err;
}
};
this.getActiveProposals = async () => {
try {
const result = await this.queries.getActiveProposals(this.spaceId);
return result;
}
catch (err) {
throw err;
}
};
this.getRecentProposals = async () => {
try {
const result = await this.queries.getRecentProposals(this.spaceId);
return result;
}
catch (err) {
throw err;
}
};
this.castVote = async (proposalId, choice, account, provider, reason) => {
try {
const client = new snapshot_js_1.default.Client712('https://hub.snapshot.org');
const result = await this.queries.getProposal(proposalId);
if (result) {
const space = result.space.id;
const proposal = proposalId;
const type = result.type;
const voteReceipt = await client.vote(provider, account, {
space: space,
proposal: proposal,
choice: choice,
type: type,
reason: reason,
});
return voteReceipt;
}
}
catch (err) {
throw err;
}
};
this.spaceId = spaceId;
}
}
exports.Snapshot = Snapshot;