@dorafactory/maci-sdk 0.0.53 → 0.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -188,17 +188,10 @@ const signupResponse = await client.maci.signup({
188
188
  gasStation: true, // Whether to use gas station
189
189
  });
190
190
 
191
- // 5. Get user state index
192
- const stateIdx = await client.maci.getStateIdxByPubKey({
193
- contractAddress: 'dora1...',
194
- pubKey: maciAccount.pubKey,
195
- });
196
-
197
- // 6. Cast vote
191
+ // 5. Cast vote
198
192
  const voteResponse = await client.maci.vote({
199
193
  signer: wallet,
200
194
  address,
201
- stateIdx,
202
195
  contractAddress: 'dora1...',
203
196
  selectedOptions: [
204
197
  { idx: 0, vc: 2 }, // Option index and voting weight
package/dist/index.js CHANGED
@@ -5505,15 +5505,23 @@ var MACI = class {
5505
5505
  async vote({
5506
5506
  signer,
5507
5507
  address,
5508
- stateIdx,
5509
5508
  contractAddress,
5510
5509
  selectedOptions,
5511
5510
  operatorCoordPubKey,
5512
5511
  maciKeypair,
5513
5512
  gasStation = false
5514
5513
  }) {
5514
+ if (maciKeypair === void 0) {
5515
+ maciKeypair = this.maciKeypair;
5516
+ }
5517
+ const stateIdx = await this.getStateIdxByPubKey({
5518
+ contractAddress,
5519
+ pubKey: maciKeypair.pubKey
5520
+ });
5515
5521
  if (stateIdx === -1) {
5516
- throw new Error("State index is not set, Please signup first");
5522
+ throw new Error(
5523
+ "State index is not set, Please signup or addNewKey first"
5524
+ );
5517
5525
  }
5518
5526
  try {
5519
5527
  const round = await this.indexer.getRoundWithFields(contractAddress, [
@@ -5565,9 +5573,6 @@ var MACI = class {
5565
5573
  if (!address) {
5566
5574
  address = (await signer.getAccounts())[0].address;
5567
5575
  }
5568
- if (maciKeypair === void 0) {
5569
- maciKeypair = this.maciKeypair;
5570
- }
5571
5576
  const plan = options.map((o) => {
5572
5577
  return [o.idx, o.vc];
5573
5578
  });
@@ -6126,8 +6131,18 @@ var MaciClient2 = class {
6126
6131
  async getVoiceCreditBalance({
6127
6132
  signer,
6128
6133
  stateIdx,
6134
+ maciKeypair,
6129
6135
  contractAddress
6130
6136
  }) {
6137
+ if (maciKeypair === void 0) {
6138
+ maciKeypair = this.maciKeypair;
6139
+ }
6140
+ if (stateIdx === void 0) {
6141
+ stateIdx = await this.getStateIdxByPubKey({
6142
+ contractAddress,
6143
+ pubKey: maciKeypair.pubKey
6144
+ });
6145
+ }
6131
6146
  return await this.maci.getVoiceCreditBalance({
6132
6147
  signer: this.getSigner(signer),
6133
6148
  stateIdx,
@@ -6287,7 +6302,6 @@ var MaciClient2 = class {
6287
6302
  async vote({
6288
6303
  signer,
6289
6304
  address,
6290
- stateIdx,
6291
6305
  contractAddress,
6292
6306
  selectedOptions,
6293
6307
  operatorCoordPubKey,
@@ -6297,7 +6311,6 @@ var MaciClient2 = class {
6297
6311
  return await this.maci.vote({
6298
6312
  signer: this.getSigner(signer),
6299
6313
  address,
6300
- stateIdx,
6301
6314
  contractAddress,
6302
6315
  selectedOptions,
6303
6316
  operatorCoordPubKey,