Skip to content

Commit

Permalink
fix: access arweave at different levels of default for esm bundle com…
Browse files Browse the repository at this point in the history
…pat PE-7069
  • Loading branch information
fedellen committed Nov 5, 2024
1 parent 944849d commit 4c75290
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 5 additions & 3 deletions examples/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h1>Upload File</h1>
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
Expand All @@ -58,7 +58,9 @@ <h1>Upload File</h1>
/**
* 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!',
Expand All @@ -80,7 +82,7 @@ <h1>Upload File</h1>
balance,
null,
2,
);
).catch((err) => console.log('Error fetching balance!', err));

/**
* Handle file upload
Expand Down
15 changes: 11 additions & 4 deletions src/common/token/arweave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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;

Expand All @@ -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(':', ''),
Expand Down

0 comments on commit 4c75290

Please sign in to comment.