kit-squared 0.2.1 → 0.2.3

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
@@ -164,13 +164,13 @@ clearAddedAccounts()
164
164
  Full details available in the [Accounts section of the docs]( https://github.com/AnAllergyToAnalogy/kit-squared/blob/main/docs/framework/ACCOUNTS.md).
165
165
 
166
166
 
167
- ## Integer types and PDAs
167
+ ## Number types and PDAs
168
168
 
169
169
  Kit² uses BigInts for dealing with integers, and will be accepted for all integer function params, and be used in all returned integer values.
170
170
 
171
- However, since PDAs pack data in a very specific way when deriving the address, when adding integers as seeds for PDAs, use the following format:
171
+ However, since PDAs pack data in a very specific way when deriving the address, when adding integers or floats as seeds for PDAs, use the following format:
172
172
  ```typescript
173
- [value, integer_type]
173
+ [value, number_type]
174
174
  ```
175
175
 
176
176
  so a `u16` with the value of `1234` would be passed as
@@ -1,5 +1,5 @@
1
1
  import { writable } from "svelte/store";
2
- import { camelToSnake, snakeToCamel, camelToPascal, snakeToPascal, getPDA, pascalToCamel, sleep } from "./utils.js";
2
+ import { camelToSnake, snakeToCamel, camelToPascal, snakeToPascal, getPDA, pascalToCamel, sleep, isIntegerType } from "./utils.js";
3
3
  import { Event } from "./utils.js";
4
4
  import { signer } from "./wallet.js";
5
5
  import { getConnection } from "./connection.js";
@@ -172,6 +172,23 @@ export async function createProgram(programClient, idl, signer = null, noEvents
172
172
  }
173
173
  return null;
174
174
  }
175
+ function _eventParamIsIntegerType(eventName_PascalCase, paramName_snakeCase) {
176
+ const types = idl.types;
177
+ for (let i = 0; i < types.length; i++) {
178
+ if (types[i].name === eventName_PascalCase) {
179
+ // found event
180
+ const fields = types[i].fields;
181
+ for (let j = 0; j < fields.length; j++) {
182
+ const field = fields[j];
183
+ if (field.name === paramName_snakeCase) {
184
+ return isIntegerType(field.type);
185
+ }
186
+ }
187
+ break;
188
+ }
189
+ }
190
+ return false;
191
+ }
175
192
  function _parseNotification(notification) {
176
193
  // slot: notification.context.slot : bigInt
177
194
  // signature: notification.value.signature : string (big sig)
@@ -194,7 +211,15 @@ export async function createProgram(programClient, idl, signer = null, noEvents
194
211
  // TODO: better integer parsing than just assuming numbers should be integers
195
212
  for (let v in decoded) {
196
213
  if (typeof decoded[v] === "number") {
197
- decoded[v] = BigInt(decoded[v]);
214
+ if (_eventParamIsIntegerType(name, camelToSnake(v))) {
215
+ //numeric type is integer
216
+ decoded[v] = BigInt(decoded[v]);
217
+ }
218
+ else {
219
+ // numberic type is float
220
+ // leave it as a number
221
+ // decoded[v] = decoded[v];
222
+ }
198
223
  }
199
224
  }
200
225
  _eventTranslation[name].trigger(decoded, slot, signature);
@@ -230,7 +255,7 @@ export async function createProgram(programClient, idl, signer = null, noEvents
230
255
  const values = codec.decode(account.data);
231
256
  for (let v in values) {
232
257
  if (typeof values[v] === "number") {
233
- values[v] = BigInt(values[v]);
258
+ values[v] = String(values[v]); // BigInt(values[v]);
234
259
  }
235
260
  }
236
261
  return values;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kit-squared",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Solana Kit functionality with SvelteKit",
5
5
  "license": "ISC",
6
6
  "author": "AnAllergyToAnalogy",