kit-squared 0.2.5 → 0.2.6

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