From 4c752909aae24eed985102511654c6361ede38a5 Mon Sep 17 00:00:00 2001 From: Derek Sonnenberg Date: Tue, 5 Nov 2024 10:20:46 -0600 Subject: [PATCH] fix: access arweave at different levels of default for esm bundle compat PE-7069 --- examples/web/index.html | 8 +++++--- src/common/token/arweave.ts | 15 +++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/examples/web/index.html b/examples/web/index.html index fdadfbb7..a521a591 100644 --- a/examples/web/index.html +++ b/examples/web/index.html @@ -37,7 +37,7 @@

Upload File

import { TurboFactory, developmentTurboConfiguration, - } from 'https://unpkg.com/@ardrive/turbo-sdk@1.13.0'; + } from 'https://unpkg.com/@ardrive/turbo-sdk'; /** * Set up our authenticated client factory @@ -58,7 +58,9 @@

Upload File

/** * Fetch fiat rates. */ - const rates = await turbo.getFiatRates(); + const rates = await turbo.getFiatRates().catch((err) => { + console.log('Error fetching rates!', err); + }); console.log( 'Successfully fetched rates!', @@ -80,7 +82,7 @@

Upload File

balance, null, 2, - ); + ).catch((err) => console.log('Error fetching balance!', err)); /** * Handle file upload diff --git a/src/common/token/arweave.ts b/src/common/token/arweave.ts index c494d17c..4d8873c8 100644 --- a/src/common/token/arweave.ts +++ b/src/common/token/arweave.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import Arweave from 'arweave'; +import ArweaveModule from 'arweave'; import { BigNumber } from 'bignumber.js'; import { Buffer } from 'node:buffer'; @@ -27,9 +27,14 @@ import { sha256B64Url, toB64Url } from '../../utils/base64.js'; import { sleep } from '../../utils/common.js'; import { TurboWinstonLogger } from '../logger.js'; +const ArweaveClass = + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore -- Access the correct class constructor for Arweave + ArweaveModule.default?.default || ArweaveModule.default || ArweaveModule; + export class ArweaveToken implements TokenTools { protected logger: TurboLogger; - protected arweave: Arweave; + protected arweave: ArweaveModule; protected mintU: boolean; protected pollingOptions: TokenPollingOptions; @@ -45,16 +50,18 @@ export class ArweaveToken implements TokenTools { }, }: { gatewayUrl?: string; - arweave?: Arweave; + arweave?: ArweaveModule; logger?: TurboLogger; mintU?: boolean; pollingOptions?: TokenPollingOptions; } = {}) { const url = new URL(gatewayUrl); + logger.info('ArweaveModule', ArweaveModule); + logger.info('ArweaveClass', ArweaveClass); this.arweave = arweave ?? - new Arweave({ + new ArweaveClass({ host: url.hostname, port: url.port, protocol: url.protocol.replace(':', ''),