Skip to content

Commit

Permalink
fix(contracts): add configuration view method and update types
Browse files Browse the repository at this point in the history
  • Loading branch information
Atticus committed Mar 22, 2024
1 parent 1bdcfeb commit 4fae4a2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/common/ant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ export class ANT implements ANTContract, BaseContract<ANTState> {
connect(signer: ContractSigner): this {
this.signer = signer;
if (this.contract instanceof RemoteContract) {
const config = this.contract.configuration();
this.contract = new WarpContract<ANTState>({
contractTxId: this.contract.contractTxId,
...config,
signer,
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/common/ar-io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ export class ArIO implements ArIOContract, BaseContract<ArIOState> {
connect(signer: ContractSigner): this {
this.signer = signer;
if (this.contract instanceof RemoteContract) {
const config = this.contract.configuration();
this.contract = new WarpContract<ArIOState>({
contractTxId: this.contract.contractTxId,
...config,
signer,
});
}
Expand Down
9 changes: 8 additions & 1 deletion src/common/contracts/remote-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
import {
BaseContract,
ContractConfiguration,
ContractSigner,
EvaluationParameters,
HTTPClient,
Expand All @@ -29,7 +30,7 @@ import { DefaultLogger } from '../logger.js';
export class RemoteContract<T> implements BaseContract<T>, ReadContract {
private logger: Logger;
private http: HTTPClient;
public readonly contractTxId: string;
private contractTxId: string;

constructor({
url = 'https://api.arns.app',
Expand All @@ -47,6 +48,12 @@ export class RemoteContract<T> implements BaseContract<T>, ReadContract {
});
}

configuration(): { contractTxId: string } {
return {
contractTxId: this.contractTxId,
};
}

/* eslint-disable */
// @ts-ignore
connect(signer: ContractSigner): this {
Expand Down
9 changes: 8 additions & 1 deletion src/common/contracts/warp-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {

import {
BaseContract,
ContractConfiguration,
ContractSigner,
EvaluationParameters,
ReadContract,
Expand All @@ -37,7 +38,7 @@ LoggerFactory.INST.setOptions({

export class WarpContract<T> implements BaseContract<T>, ReadContract {
private contract: Contract<T>;
protected contractTxId: string;
private contractTxId: string;
private cacheUrl: string | undefined;

constructor({
Expand All @@ -57,6 +58,12 @@ export class WarpContract<T> implements BaseContract<T>, ReadContract {
this.cacheUrl = cacheUrl;
}

configuration(): { contractTxId: string } {
return {
contractTxId: this.contractTxId,
};
}

// base contract methods
connect(signer: ContractSigner) {
// TODO: Update type to use Signer interface
Expand Down

0 comments on commit 4fae4a2

Please sign in to comment.