Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: access arweave at different levels of default for esm bundle compat PE-7069 #206

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 9 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;
Comment on lines +30 to +33
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider making this an export and using it where we want to use Arweave

Copy link
Collaborator Author

@fedellen fedellen Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now we just access it here and then in test env. using this exported version in our test env just causes compiler issues due to this being a const. as arweave-js exports right now, it seems like we need this pattern in each non-test file that we try to access init or new


export class ArweaveToken implements TokenTools {
protected logger: TurboLogger;
protected arweave: Arweave;
protected arweave: ArweaveModule;
protected mintU: boolean;
protected pollingOptions: TokenPollingOptions;

Expand All @@ -45,7 +50,7 @@ export class ArweaveToken implements TokenTools {
},
}: {
gatewayUrl?: string;
arweave?: Arweave;
arweave?: ArweaveModule;
logger?: TurboLogger;
mintU?: boolean;
pollingOptions?: TokenPollingOptions;
Expand All @@ -54,7 +59,7 @@ export class ArweaveToken implements TokenTools {

this.arweave =
arweave ??
new Arweave({
new ArweaveClass({
host: url.hostname,
port: url.port,
protocol: url.protocol.replace(':', ''),
Expand Down
Loading