kit-squared 0.2.4 → 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.
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  [Skip to Contents](#contents)
8
8
 
9
- [Skip to Example Project](https://github.com/AnAllergyToAnalogy/kit-squared/tree/main/example)
9
+ [Skip to Example Project](https://github.com/AnAllergyToAnalogy/kit-squared-example-site/tree/main/src)
10
10
 
11
11
  ## Initialising
12
12
 
@@ -194,7 +194,7 @@ The library requires no additional features or functionality for interacting wit
194
194
 
195
195
  The [@solana-program/token-2022](https://www.npmjs.com/package/@solana-program/token-2022) package will be supported after its next release. It currently has outdated peer dependencies that I have patched with a PR. These are slow moving wheels beyond my control.
196
196
 
197
- You can retreive the RPC of your Kit2 instance with
197
+ You can retreive the RPC of your Kit² instance with
198
198
  ```typescript
199
199
  const rpc = (getConnection()).rpc;
200
200
  ```
@@ -227,5 +227,5 @@ Managing accounts included in instructions and transactions.
227
227
  ### [Utils](https://github.com/AnAllergyToAnalogy/kit-squared/blob/main/docs/utils/UTILS.md)
228
228
  Various utilities, some relating specific to Solana, others that are more broadly used by this library.
229
229
 
230
- ### [Example](https://github.com/AnAllergyToAnalogy/kit-squared/tree/main/example)
230
+ ### [Example](https://github.com/AnAllergyToAnalogy/kit-squared-example-site/tree/main/src)
231
231
  An example repo showing basic usage of the Kit² library.
@@ -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,
@@ -276,7 +276,7 @@ export function parseSeconds(time) {
276
276
  let days = time / 24n;
277
277
  let parsed = p(hours) + ":" + p(minutes) + ":" + p(seconds);
278
278
  if (days) {
279
- parsed = p(days) + parsed;
279
+ parsed = p(days) + ":" + parsed;
280
280
  }
281
281
  return parsed;
282
282
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kit-squared",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Solana Kit functionality with SvelteKit",
5
5
  "license": "ISC",
6
6
  "author": "AnAllergyToAnalogy",