kit-squared 0.2.5 → 0.2.7

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.
@@ -77,6 +77,7 @@ export async function transact(ixs = [], names = []) {
77
77
  onConfirm.trigger(names);
78
78
  }
79
79
  catch (e) {
80
+ console.error(e);
80
81
  if (_txWasCancelled(e)) {
81
82
  // TODO: properly catch this and other errors
82
83
  onCancel.trigger(names);
@@ -116,14 +117,16 @@ export async function createProgram(programClient, idl, signer = null, noEvents
116
117
  const _eventTranslation = {};
117
118
  // Events
118
119
  const _events = {};
119
- for (let event of idl.events) {
120
- const nameCamel = pascalToCamel(event.name);
121
- _events[event.name] = {
122
- name: nameCamel,
123
- discriminator: event.discriminator,
124
- codec: programClient[`get${event.name}Codec`](),
125
- };
126
- _eventTranslation[nameCamel] = Event();
120
+ if (idl.events) {
121
+ for (let event of idl.events) {
122
+ const nameCamel = pascalToCamel(event.name);
123
+ _events[event.name] = {
124
+ name: nameCamel,
125
+ discriminator: event.discriminator,
126
+ codec: programClient[`get${event.name}Codec`](),
127
+ };
128
+ _eventTranslation[nameCamel] = Event();
129
+ }
127
130
  }
128
131
  // Set up an abort controller.
129
132
  const abortController = new AbortController();
@@ -351,9 +354,10 @@ export async function createProgram(programClient, idl, signer = null, noEvents
351
354
  // use [property] of that.
352
355
  // Will need to infer type from the account
353
356
  const accountData = await readAccount(seed.account, ixProps[parentName]);
357
+ const propertyCamel = snakeToCamel(property);
354
358
  if (!accountData)
355
359
  throw new Error(`Unable to read account relating to ${seed.account}: ${ixProps[parentName]}`);
356
- const value = accountData[property];
360
+ const value = accountData[propertyCamel];
357
361
  const propertyType = getAccountPropertyType(seed.account, property);
358
362
  if (!propertyType)
359
363
  throw new Error(`Unable to read property type relating to ${seed.account}: ${property}`);
@@ -400,44 +404,48 @@ export async function createProgram(programClient, idl, signer = null, noEvents
400
404
  }
401
405
  }
402
406
  }
403
- for (let instruction of idl.instructions) {
404
- const name = instruction.name;
405
- const nameCamel = snakeToCamel(name);
406
- const NamePascal = snakeToPascal(name);
407
- const argTypes = instruction.args;
408
- ixs[nameCamel] = async function () {
409
- if (arguments.length !== argTypes.length) {
410
- throw new Error(`Incorrect arguments provided for ${name}. Received ${arguments.length}, expected ${argTypes.length}.`);
411
- }
412
- let ixProps = {};
413
- for (let account in addedAccounts) {
414
- ixProps[account] = addedAccounts[account];
415
- }
416
- for (let i = 0; i < arguments.length; i++) {
417
- ixProps[snakeToCamel(argTypes[i].name)] = arguments[i];
418
- }
419
- await addIxAccounts(instruction, ixProps);
420
- return programClient[`get${NamePascal}Instruction`](ixProps);
421
- };
422
- tx[nameCamel] = async function () {
423
- let ix = await ixs[nameCamel](...arguments);
424
- await transactSingle(ix, nameCamel);
425
- };
407
+ if (idl.instructions) {
408
+ for (let instruction of idl.instructions) {
409
+ const name = instruction.name;
410
+ const nameCamel = snakeToCamel(name);
411
+ const NamePascal = snakeToPascal(name);
412
+ const argTypes = instruction.args;
413
+ ixs[nameCamel] = async function () {
414
+ if (arguments.length !== argTypes.length) {
415
+ throw new Error(`Incorrect arguments provided for ${name}. Received ${arguments.length}, expected ${argTypes.length}.`);
416
+ }
417
+ let ixProps = {};
418
+ for (let account in addedAccounts) {
419
+ ixProps[account] = addedAccounts[account];
420
+ }
421
+ for (let i = 0; i < arguments.length; i++) {
422
+ ixProps[snakeToCamel(argTypes[i].name)] = arguments[i];
423
+ }
424
+ await addIxAccounts(instruction, ixProps);
425
+ return programClient[`get${NamePascal}Instruction`](ixProps);
426
+ };
427
+ tx[nameCamel] = async function () {
428
+ let ix = await ixs[nameCamel](...arguments);
429
+ await transactSingle(ix, nameCamel);
430
+ };
431
+ }
426
432
  }
427
433
  let account = {};
428
- for (let a of idl.accounts) {
429
- const nameCamel = pascalToCamel(a.name);
430
- account[nameCamel] = async function (addressOrSeeds) {
431
- if (Array.isArray(addressOrSeeds)) {
432
- // it's array, assume it's seeds
433
- const address = await pda(addressOrSeeds);
434
- return await readAccount(nameCamel, address);
435
- }
436
- else {
437
- // assume address
438
- return await readAccount(nameCamel, addressOrSeeds);
439
- }
440
- };
434
+ if (idl.accounts) {
435
+ for (let a of idl.accounts) {
436
+ const nameCamel = pascalToCamel(a.name);
437
+ account[nameCamel] = async function (addressOrSeeds) {
438
+ if (Array.isArray(addressOrSeeds)) {
439
+ // it's array, assume it's seeds
440
+ const address = await pda(addressOrSeeds);
441
+ return await readAccount(nameCamel, address);
442
+ }
443
+ else {
444
+ // assume address
445
+ return await readAccount(nameCamel, addressOrSeeds);
446
+ }
447
+ };
448
+ }
441
449
  }
442
450
  const returns = {
443
451
  on,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kit-squared",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Solana Kit functionality with SvelteKit",
5
5
  "license": "ISC",
6
6
  "author": "AnAllergyToAnalogy",