Skip to content

Commit

Permalink
feat: split TulipeContractPlaceholder's ARS in two methods like for s…
Browse files Browse the repository at this point in the history
…igner
  • Loading branch information
0Lilian committed Sep 4, 2022
1 parent b5fd6e5 commit 7091cf3
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/composables/proxies/contract/placeholder.js
Expand Up @@ -76,36 +76,37 @@ export class TulipeContractPlaceholder extends TulipePlaceholder {
}
}

_initEthersInstanceARS () {

_initARS (address, abi) {
// 1) Purge old ethersInstance ARS
this._purgeARS()

// 2) Auto-update status when provider status is WRONG, DISCONNECTED or in ERROR
// 1) Automatically update the contract ethersInstance when the signer changes.
this._ars.unwatchers.push(
dapp.provider.status.watchAny((status) => {
if (status === "WRONG_NETWORK") {
this.status.set("UNAVAILABLE");
}
else if (["DISCONNECTED", "ERROR"].includes(status)) {
this.status.set("NO_PROVIDER");
}
})
);

// 3) Automatically update the contract ethersInstance when the signer changes.
this._ars.unwatchers.push(
watch ([dapp.signer.isSafe], (newValue, oldValue) => {
watch(dapp.signer.isSafe, (newValue, oldValue) => {
if (newValue !== oldValue) {
// Here the contract is removed and then recreated in order to fully destroy the old signer and provider.
// contract.signer and contract.provider attributes are read-only and it's at the moment the proper solution.
const abi = this.proxy.ethersInstance.interface
const address = this.proxy.ethersInstance.address
this.proxy.ethersInstance = null;
this._updateContract(address, abi);
}
})
);
}

_initPlaceholderInstanceARS () {

// 1) Purge old ethersInstance ARS
dapp.provider.status.watchAny((status) => {
if (status === "WRONG_NETWORK") {
this.status.set("UNAVAILABLE");
}
else if (["DISCONNECTED", "ERROR"].includes(status)) {
this.status.set("NO_PROVIDER");
}
})

}

async _asyncInit () {
this.proxy._initIsRunning = true;

Expand All @@ -118,11 +119,10 @@ export class TulipeContractPlaceholder extends TulipePlaceholder {
}

// Else, perform some initializations
else {
// else {}

// Initialize the signer ARS
this._initARS()
}
// Initialize the signer ARS
this._initARS()

this.proxy._initIsRunning = false;
}.bind(this))
Expand Down

0 comments on commit 7091cf3

Please sign in to comment.