From 227aa730122f218f8f24791f72d6aae5f7e775df Mon Sep 17 00:00:00 2001 From: Den Date: Sat, 20 Jul 2024 22:35:19 +0200 Subject: [PATCH] fix: use deserializer from options if specified --- packages/near-sdk-js/lib/utils.js | 7 +++---- packages/near-sdk-js/src/utils.ts | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/near-sdk-js/lib/utils.js b/packages/near-sdk-js/lib/utils.js index 93a1ca281..c858e818c 100644 --- a/packages/near-sdk-js/lib/utils.js +++ b/packages/near-sdk-js/lib/utils.js @@ -31,14 +31,13 @@ export function assert(expression, message) { throw new Error("assertion failed: " + message); } } -export function getValueWithOptions(subDatatype, value, options = { - deserializer: deserialize, -}) { +export function getValueWithOptions(subDatatype, value, options = {}) { if (value === null) { return options?.defaultValue ?? null; } + const deserializer = options.deserializer || deserialize; // here is an obj - let deserialized = deserialize(value); + let deserialized = deserializer(value); if (deserialized === undefined || deserialized === null) { return options?.defaultValue ?? null; } diff --git a/packages/near-sdk-js/src/utils.ts b/packages/near-sdk-js/src/utils.ts index 90b57e044..3c4ac140c 100644 --- a/packages/near-sdk-js/src/utils.ts +++ b/packages/near-sdk-js/src/utils.ts @@ -69,16 +69,16 @@ export type Mutable = { -readonly [P in keyof T]: T[P] }; export function getValueWithOptions( subDatatype: unknown, value: Uint8Array | null, - options: Omit, "serializer"> = { - deserializer: deserialize, - } + options: Omit, "serializer"> = {} ): DataType | null { if (value === null) { return options?.defaultValue ?? null; } + const deserializer = options.deserializer || deserialize; + // here is an obj - let deserialized = deserialize(value); + let deserialized = deserializer(value); if (deserialized === undefined || deserialized === null) { return options?.defaultValue ?? null;