kit-squared 0.2.0 → 0.2.2

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.
@@ -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;
@@ -37,7 +37,7 @@ export function isNumberType(type) {
37
37
  // return e;
38
38
  // })();
39
39
  export const typeEncoder = (() => {
40
- const types = ["Address", "f32", "f64"];
40
+ const types = ["Address", "F32", "F64"];
41
41
  for (let i = 0; i < 5; i++) {
42
42
  const s = 8 * (2 ** i);
43
43
  types.push("U" + s);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kit-squared",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Solana Kit functionality with SvelteKit",
5
5
  "license": "ISC",
6
6
  "author": "AnAllergyToAnalogy",