Skip to content

Commit

Permalink
chore: sync configuration options for both channel versions
Browse files Browse the repository at this point in the history
  • Loading branch information
penovicp committed Sep 25, 2024
1 parent 88c00f8 commit 9e6cbf1
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/channel/rpc_0_6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,24 @@ export class RpcChannel {

private specVersion?: string;

private transactionRetryIntervalFallback?: number;

readonly waitMode: Boolean; // behave like web2 rpc and return when tx is processed

private batchClient?: BatchClient;

constructor(optionsOrProvider?: RpcProviderOptions) {
const { nodeUrl, retries, headers, blockIdentifier, chainId, specVersion, waitMode, batch } =
optionsOrProvider || {};
const {
nodeUrl,
retries,
headers,
blockIdentifier,
chainId,
specVersion,
waitMode,
transactionRetryIntervalFallback,
batch,
} = optionsOrProvider || {};
if (Object.values(NetworkName).includes(nodeUrl as NetworkName)) {
this.nodeUrl = getDefaultNodeUrl(nodeUrl as NetworkName, optionsOrProvider?.default);
} else if (nodeUrl) {
Expand All @@ -72,6 +83,7 @@ export class RpcChannel {
this.specVersion = specVersion;
this.waitMode = waitMode || false;
this.requestId = 0;
this.transactionRetryIntervalFallback = transactionRetryIntervalFallback;

if (typeof batch === 'number') {
this.batchClient = new BatchClient({
Expand All @@ -82,6 +94,10 @@ export class RpcChannel {
}
}

private get transactionRetryIntervalDefault() {
return this.transactionRetryIntervalFallback ?? 5000;
}

public setChainId(chainId: StarknetChainId) {
this.chainId = chainId;
}
Expand Down Expand Up @@ -267,7 +283,7 @@ export class RpcChannel {
let { retries } = this;
let onchain = false;
let isErrorState = false;
const retryInterval = options?.retryInterval ?? 5000;
const retryInterval = options?.retryInterval ?? this.transactionRetryIntervalDefault;
const errorStates: any = options?.errorStates ?? [
RPC.ETransactionStatus.REJECTED,
// TODO: commented out to preserve the long-standing behavior of "reverted" not being treated as an error by default
Expand Down

0 comments on commit 9e6cbf1

Please sign in to comment.