Skip to content

Commit

Permalink
solving conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Viterbo committed Jun 14, 2024
2 parents a35d990 + 733191f commit 05838c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 37 deletions.
18 changes: 8 additions & 10 deletions src/antelope/stores/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,10 @@ export const useChainStore = defineStore(store_name, {
this.trace('updateChainData');
useFeedbackStore().setLoading('updateChainData');
try {
const chain = useChainStore().getChain(label);
const chain = this.getChain(label);
const now = Date.now();
const tolerance = 10 * 60 * 1000; // 10 minutes
const lastUpdate = chain.lastUpdate;
const isUpToDate = now - lastUpdate < tolerance;
this.trace('updateChainData', { isUpToDate, now, lastUpdate, tolerance });
const tolerance = 1000 * 10; // 10 seconds
const isUpToDate = now - chain.lastUpdate < tolerance;
if (isUpToDate) {
// This avoid to update the chain data if the user switches from one chain to another and back
this.trace('updateChainData', label, '-> already up to date');
Expand Down Expand Up @@ -200,7 +198,7 @@ export const useChainStore = defineStore(store_name, {
async updateStakedRatio(label: string): Promise<void> {
// first we need the contract instance to be able to execute queries
this.trace('updateStakedRatio', label);
const chain = useChainStore().getChain(label);
const chain = this.getChain(label);
try {
useFeedbackStore().setLoading('updateStakedRatio');
if (!chain.settings.isNative()) {
Expand Down Expand Up @@ -284,10 +282,10 @@ export const useChainStore = defineStore(store_name, {
},
setStakedRatio(label: string, ratio: ethers.BigNumber) {
this.trace('setStakedRatio', label, ratio.toString());
const chain = useChainStore().getChain(label);
const chain = this.getChain(label);
try {
if (!chain.settings.isNative()) {
const decimals = (useChainStore().getChain(label).settings as EVMChainSettings).getStakedSystemToken().decimals;
const decimals = (this.getChain(label).settings as EVMChainSettings).getStakedSystemToken().decimals;
const ratioNumber = parseFloat(ethers.utils.formatUnits(ratio, decimals));
this.trace('setStakedRatio', label, ratio.toString(), ratioNumber);
(this.__chains[label] as EvmChainModel).stakeRatio = ratio;
Expand All @@ -304,10 +302,10 @@ export const useChainStore = defineStore(store_name, {
},
setUnstakedRatio(label: string, ratio: ethers.BigNumber) {
this.trace('setUnstakedRatio', label, ratio.toString());
const chain = useChainStore().getChain(label);
const chain = this.getChain(label);
try {
if (!chain.settings.isNative()) {
const decimals = (useChainStore().getChain(label).settings as EVMChainSettings).getStakedSystemToken().decimals;
const decimals = (this.getChain(label).settings as EVMChainSettings).getStakedSystemToken().decimals;
const ratioNumber = parseFloat(ethers.utils.formatUnits(ratio, decimals));
this.trace('setUnstakedRatio', label, ratio.toString(), ratioNumber);
(this.__chains[label] as EvmChainModel).unstakeRatio = ratio;
Expand Down
39 changes: 12 additions & 27 deletions src/antelope/stores/rex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,10 @@ export const useRexStore = defineStore(store_name, {
async updateWithdrawable(label: string) {
this.trace('updateWithdrawable', label);
if (this.isNetworkEVM(label)) {
try {
const contract = await this.getEscrowContractInstance(label);
const address = useAccountStore().getAccount(label).account;
const withdrawable = await contract.maxWithdraw(address);
this.setWithdrawable(label, withdrawable);
} catch (error) {
console.error('updateWithdrawable', label, error);
throw error;
}
const contract = await this.getEscrowContractInstance(label);
const address = useAccountStore().getAccount(label).account;
const withdrawable = await contract.maxWithdraw(address);
this.setWithdrawable(label, withdrawable);
} else {
this.trace('updateWithdrawable', label, 'not supported for native chains yet');
}
Expand All @@ -223,15 +218,10 @@ export const useRexStore = defineStore(store_name, {
async updateDeposits(label: string) {
this.trace('updateDeposits', label);
if (this.isNetworkEVM(label)) {
try {
const contract = await this.getEscrowContractInstance(label);
const address = useAccountStore().getAccount(label).account;
const deposits = await contract.depositsOf(address);
this.setDeposits(label, deposits);
} catch (error) {
console.error('updateDeposits', label, error);
throw error;
}
const contract = await this.getEscrowContractInstance(label);
const address = useAccountStore().getAccount(label).account;
const deposits = await contract.depositsOf(address);
this.setDeposits(label, deposits);
} else {
console.error('updateDeposits', label, 'not supported for native chains yet');
}
Expand All @@ -244,15 +234,10 @@ export const useRexStore = defineStore(store_name, {
async updateBalance(label: string) {
this.trace('updateBalance', label);
if (this.isNetworkEVM(label)) {
try {
const contract = await this.getStakedSystemContractInstance(label);
const address = useAccountStore().getAccount(label).account;
const balance = await contract.balanceOf(address);
this.setBalance(label, balance);
} catch (error) {
console.error('updateBalance', label, error);
throw error;
}
const contract = await this.getEscrowContractInstance(label);
const address = useAccountStore().getAccount(label).account;
const balance = await contract.balanceOf(address);
this.setBalance(label, balance);
} else {
console.error('updateBalance', label, 'not supported for native chains yet');
}
Expand Down

0 comments on commit 05838c0

Please sign in to comment.