UNPKG

@ledgerhq/coin-stellar

Version:
48 lines 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.unpatchHermesTypedArrays = exports.patchHermesTypedArraysIfNeeded = void 0; const logs_1 = require("@ledgerhq/logs"); /* * This whole patch thing is messy: * It's goal is to: Fix error when sending a token transaction in Stellar * It originally was in ledger-mobile polyfill.ts (https://github.com/LedgerHQ/ledger-live/pull/9687) * But globally patching is not a good idea, and broke the polkadot sdk */ // Save original methods once at app startup const OriginalTypedArrayMethods = { subarray: Uint8Array.prototype.subarray, slice: Uint8Array.prototype.slice, map: Uint8Array.prototype.map, filter: Uint8Array.prototype.filter, }; // Track whether we actually patched let hermesTypedArrayPatched = false; function patchHermesTypedArraysIfNeeded() { if (global.HermesInternal && !hermesTypedArrayPatched) { try { (0, logs_1.log)("coin:stellar", "🔵 Patching TypedArray because of Hermes bug"); // Only require the module when we're actually running on Hermes // eslint-disable-next-line @typescript-eslint/no-var-requires const fixHermesTypedArrayBug = require("@exodus/patch-broken-hermes-typed-arrays"); fixHermesTypedArrayBug(); hermesTypedArrayPatched = true; } catch { (0, logs_1.log)("coin:stellar", "Failed to patch typed arrays"); } } } exports.patchHermesTypedArraysIfNeeded = patchHermesTypedArraysIfNeeded; function unpatchHermesTypedArrays() { if (hermesTypedArrayPatched) { const TypedArray = Object.getPrototypeOf(Uint8Array); TypedArray.prototype.subarray = OriginalTypedArrayMethods.subarray; TypedArray.prototype.slice = OriginalTypedArrayMethods.slice; TypedArray.prototype.map = OriginalTypedArrayMethods.map; TypedArray.prototype.filter = OriginalTypedArrayMethods.filter; (0, logs_1.log)("coin:stellar", "🟢 Reverted TypedArray methods to originals"); hermesTypedArrayPatched = false; // reset } } exports.unpatchHermesTypedArrays = unpatchHermesTypedArrays; //# sourceMappingURL=polyfill.js.map