Skip to content

Commit 908d1c7

Browse files
TodmyChaituVR
andauthored
feat(proposal-update): add ability to update proposal (#895)
* feat(proposal-update): add ability to update proposal * fix(proposal update): fix proposal update schema * feat(semver): update the version of the lib * fix(ts): fix UpdateProposal type * chore(version): Update package.json version Co-authored-by: Chaitanya <[email protected]> * fix(types): update types --------- Co-authored-by: Chaitanya <[email protected]>
1 parent f27a363 commit 908d1c7

File tree

6 files changed

+99
-1
lines changed

6 files changed

+99
-1
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.5.10",
3+
"version": "0.6.0",
44
"repository": "snapshot-labs/snapshot.js",
55
"license": "MIT",
66
"main": "dist/snapshot.cjs.js",

src/schemas/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import space from './space.json';
22
import proposal from './proposal.json';
3+
import updateProposal from './update-proposal.json';
34
import vote from './vote.json';
45
import profile from './profile.json';
56
import statement from './statement.json';
@@ -8,6 +9,7 @@ import zodiac from './zodiac.json';
89
export default {
910
space: space.definitions.Space,
1011
proposal: proposal.definitions.Proposal,
12+
updateProposal: updateProposal.definitions.UpdateProposal,
1113
vote: vote.definitions.Vote,
1214
profile: profile.definitions.Profile,
1315
statement: statement.definitions.Statement,

src/schemas/update-proposal.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/UpdateProposal",
4+
"definitions": {
5+
"UpdateProposal": {
6+
"title": "Update Proposal",
7+
"type": "object",
8+
"properties": {
9+
"proposal": {
10+
"type": "string",
11+
"title": "proposal id"
12+
},
13+
"name": {
14+
"type": "string",
15+
"title": "name",
16+
"minLength": 1,
17+
"maxLength": 256
18+
},
19+
"body": {
20+
"type": "string",
21+
"title": "body",
22+
"minLength": 0,
23+
"maxLength": 20000
24+
},
25+
"discussion": {
26+
"type": "string",
27+
"format": "customUrl",
28+
"title": "discussion",
29+
"maxLength": 256
30+
},
31+
"choices": {
32+
"type": "array",
33+
"title": "choices",
34+
"minItems": 1,
35+
"maxItems": 500
36+
},
37+
"type": {
38+
"enum": [
39+
"single-choice",
40+
"approval",
41+
"ranked-choice",
42+
"quadratic",
43+
"weighted",
44+
"custom",
45+
"basic"
46+
]
47+
},
48+
"metadata": {
49+
"type": "object",
50+
"title": "metadata"
51+
}
52+
},
53+
"required": ["proposal", "name", "body", "discussion", "choices", "type", "metadata"],
54+
"additionalProperties": false
55+
}
56+
}
57+
}

src/sign/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getAddress } from '@ethersproject/address';
55
import {
66
Space,
77
Proposal,
8+
UpdateProposal,
89
CancelProposal,
910
Vote,
1011
Follow,
@@ -17,6 +18,7 @@ import {
1718
Statement,
1819
spaceTypes,
1920
proposalTypes,
21+
updateProposalTypes,
2022
cancelProposalTypes,
2123
cancelProposal2Types,
2224
voteTypes,
@@ -111,6 +113,14 @@ export default class Client {
111113
return await this.sign(web3, address, message, proposalTypes);
112114
}
113115

116+
async updateProposal(
117+
web3: Web3Provider | Wallet,
118+
address: string,
119+
message: UpdateProposal
120+
) {
121+
return await this.sign(web3, address, message, updateProposalTypes);
122+
}
123+
114124
async cancelProposal(
115125
web3: Web3Provider | Wallet,
116126
address: string,

src/sign/types.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"6fee59b7db10fabbb0c6420c0a18c9d2c36306e342042826a355bfc7fe733870": "proposal",
55
"9ff8af4cfb586e2c7962d792b99328fb47e8a4e73cc89873c0980484bc1063a5": "delete-proposal",
66
"734df82cdad586386defa4cb55adda7cb1b2a56929c4e6c3dc676f9901947288": "delete-proposal",
7+
"4e5fa89616761defa1274103441809c8445f8404306890ad36ec653d90201d58": "update-proposal",
78
"50084aae0fe117c83ddf855557dde35ae2872e9045443a15f72aa6c68ea3943b": "vote",
89
"1dfe3863f6333a85581fb150d4ee77c95a6d026c518ca1b11c08ae1d98acd598": "vote-array",
910
"1814c3dd303c5919ce488b924f92b9a42a0834972f514e55b1879fda48e67736": "vote-string",

src/sign/types.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ export interface Proposal {
2929
app?: string;
3030
}
3131

32+
export interface UpdateProposal {
33+
proposal: string;
34+
from: string;
35+
space: string;
36+
timestamp: number;
37+
type: ProposalType;
38+
title: string;
39+
body: string;
40+
discussion: string;
41+
choices: string[];
42+
plugins: string;
43+
}
44+
3245
export interface CancelProposal {
3346
from?: string;
3447
space: string;
@@ -126,6 +139,21 @@ export const proposalTypes = {
126139
]
127140
};
128141

142+
export const updateProposalTypes = {
143+
UpdateProposal: [
144+
{ name: 'proposal', type: 'string' },
145+
{ name: 'from', type: 'address' },
146+
{ name: 'space', type: 'string' },
147+
{ name: 'timestamp', type: 'uint64' },
148+
{ name: 'type', type: 'string' },
149+
{ name: 'title', type: 'string' },
150+
{ name: 'body', type: 'string' },
151+
{ name: 'discussion', type: 'string' },
152+
{ name: 'choices', type: 'string[]' },
153+
{ name: 'plugins', type: 'string' }
154+
]
155+
};
156+
129157
export const cancelProposalTypes = {
130158
CancelProposal: [
131159
{ name: 'from', type: 'address' },

0 commit comments

Comments
 (0)