Skip to content

Commit

Permalink
Merge pull request #640 from telosnetwork/develop
Browse files Browse the repository at this point in the history
v2.3.2-rc
  • Loading branch information
pmjanus authored Nov 20, 2023
2 parents 19d4c6e + 007e631 commit 7b2cd28
Show file tree
Hide file tree
Showing 95 changed files with 4,695 additions and 3,577 deletions.
2 changes: 1 addition & 1 deletion env.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const sharedEnv = {
GOOGLE_ANALYTICS: 'UA-154600181-2',
IMGUR_CLIENT_ID: 'b6f46df9d1da9d9',
EVM_CONTRACT: 'eosio.evm',
PROJECT_ID: '14ec76c44bae7d461fa0f5fd5f8a9da1',
PROJECT_ID: '2392473d6d98499c7138cd2d705a791f',
};

const TESTNET = {
Expand Down
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ module.exports = {
//TODO increase thresholds as coverage increases as testing will be enforced
coverageThreshold: {
global: {
statements: 5.84,
statements: 4.02,
branches: 4.84,
functions: 2.29,
lines: 6.07,
functions: 1.34,
lines: 4.16,
},
'./src/components/': {
statements: 0,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "telos-web-wallet",
"version": "2.3.1",
"version": "2.3.2",
"description": "A Web Wallet for Telos",
"productName": "Telos Web Wallet",
"private": true,
Expand All @@ -21,7 +21,7 @@
"@wagmi/core": "^1.3.7",
"@web3modal/ethereum": "2.7.0",
"@web3modal/html": "2.7.0",
"axios": "^0.21.1",
"axios": "^1.6.1",
"babel-loader": "^8.1.0",
"bignumber.js": "^9.0.1",
"core-js": "^3.6.5",
Expand Down
332 changes: 214 additions & 118 deletions src/antelope/chains/EVMChainSettings.ts

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions src/antelope/chains/NativeChainSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
import { RpcEndpoint } from 'universal-authenticator-library';
import {
Name,
Expand Down Expand Up @@ -38,8 +38,9 @@ import {
TransactionV1,
TokenSourceInfo,
TokenBalance,
NFTClass,
IndexerTransactionsFilter,
Collectible,
IndexerAccountNftsFilter,
IndexerCollectionNftsFilter,
} from 'src/antelope/types';
import { ethers } from 'ethers';
import { toStringNumber } from 'src/antelope/stores/utils/currency-utils';
Expand Down Expand Up @@ -75,12 +76,13 @@ export default abstract class NativeChainSettings implements ChainSettings {
let pendingRequests = 0;

// Interceptor handlers -- these handlers are used to limit the number of concurrent requests
const requestHandler = (config: AxiosRequestConfig) => new Promise((resolve) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const requestHandler = (value: InternalAxiosRequestConfig) => new Promise<InternalAxiosRequestConfig<any>>((resolve) => {
const interval = setInterval(() => {
if (pendingRequests < MAX_REQUESTS_COUNT) {
pendingRequests++;
clearInterval(interval);
resolve(config);
resolve(value);
}
}, INTERVAL_MS);
});
Expand Down Expand Up @@ -158,12 +160,12 @@ export default abstract class NativeChainSettings implements ChainSettings {
*/
abstract getSystemTokens(): TokenClass[];

async getNFTsInventory(owner: string, filter: IndexerTransactionsFilter): Promise<NFTClass[]> {
throw new Error('Method not implemented yet getNFTsInventory() ' + + JSON.stringify({ ...filter, owner }));
async getNftsForAccount(owner: string, filter: IndexerAccountNftsFilter): Promise<Collectible[]> {
throw new Error('Method not implemented yet getNftsForAccount() ' + + JSON.stringify({ ...filter, owner }));
}

async getNFTsCollection(contract: string, filter: IndexerTransactionsFilter): Promise<NFTClass[]> {
throw new Error('Method not implemented yet getNFTsCollection()' + JSON.stringify({ ...filter, contract }));
async getNftsForCollection(contract: string, filter: IndexerCollectionNftsFilter): Promise<Collectible[]> {
throw new Error('Method not implemented yet getNftsForCollection()' + JSON.stringify({ ...filter, contract }));
}

constructTokenId(token: TokenClass): string {
Expand Down
4 changes: 2 additions & 2 deletions src/antelope/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getAntelope } from 'src/antelope';
import { AntelopeError, AntelopeErrorPayload } from 'src/antelope/types';

export class AntelopeConfig {
wrapError(description: string, error: unknown): AntelopeError {
transactionError(description: string, error: unknown): AntelopeError {
if (error instanceof AntelopeError) {
return error as AntelopeError;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ export class AntelopeConfig {
this.__notify_success_copy_handler = handler;
}

public setnotifyFailureMessage(handler: (message: string, payload?: AntelopeErrorPayload) => void) {
public setNotifyFailureMessage(handler: (message: string, payload?: AntelopeErrorPayload) => void) {
this.__notify_failure_message_handler = handler;
}

Expand Down
24 changes: 12 additions & 12 deletions src/antelope/stores/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import {
useAccountStore,
useFeedbackStore,
useChainStore,
useEVMStore,
CURRENT_CONTEXT,
useContractStore,
} from 'src/antelope';
import { formatWei } from 'src/antelope/stores/utils';
import { BigNumber, ethers } from 'ethers';
Expand Down Expand Up @@ -127,7 +127,7 @@ export const useBalancesStore = defineStore(store_name, {
// We need to get the value ready to overwrite immediately and therefore avoid the blink
const wrapTokens = chain_settings.getWrappedSystemToken();
const authenticator = account.authenticator as EVMAuthenticator;
const wrapBalance = await authenticator.getERC20TokenBalance(account.account, wrapTokens.address);
const wrapBalance = await authenticator.getERC20TokenBalance(account.account, wrapTokens.address as addressString);

// now we call the indexer
const newBalances = await chain_settings.getBalances(account.account);
Expand Down Expand Up @@ -166,7 +166,7 @@ export const useBalancesStore = defineStore(store_name, {
const authenticator = account.authenticator as EVMAuthenticator;
const promises = tokens
.filter(token => token.address !== chain_settings.getSystemToken().address)
.map(token => authenticator.getERC20TokenBalance(account.account, token.address)
.map(token => authenticator.getERC20TokenBalance(account.account, token.address as addressString)
.then((balanceBn: BigNumber) => {
this.processBalanceForToken(label, token, balanceBn);
}).catch((error) => {
Expand Down Expand Up @@ -244,7 +244,7 @@ export const useBalancesStore = defineStore(store_name, {
this.processBalanceForToken(label, sys_token, balanceBn);
} catch (error) {
console.error(error);
throw getAntelope().config.wrapError('antelope.evm.error_update_system_balance_failed', error);
throw getAntelope().config.transactionError('antelope.evm.error_update_system_balance_failed', error);
}
},
shouldAddTokenBalance(label: string, balanceBn: BigNumber, token: TokenClass): boolean {
Expand Down Expand Up @@ -294,7 +294,7 @@ export const useBalancesStore = defineStore(store_name, {
async prepareWagmiTokenTransferConfig(label: Label, token: TokenClass, to: string, amount: BigNumber): Promise<void> {
const config = (await prepareWriteContract({
address: token.address as addressString,
abi: useEVMStore().getTokenABI(token.type),
abi: useContractStore().getTokenABI(token.type),
functionName: 'transfer',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
args: [to, amount] as any[],
Expand All @@ -303,7 +303,7 @@ export const useBalancesStore = defineStore(store_name, {
this.setWagmiTokenTransferConfig(config, label);
this.setWagmiSystemTokenTransferConfig(null, label);
},
async transferTokens(token: TokenClass, to: string, amount: BigNumber, memo?: string): Promise<TransactionResponse> {
async transferTokens(token: TokenClass, to: addressString, amount: BigNumber, memo?: string): Promise<TransactionResponse> {
const funcname = 'transferTokens';
this.trace(funcname, token, to, amount.toString(), memo);
const label = CURRENT_CONTEXT;
Expand All @@ -322,7 +322,7 @@ export const useBalancesStore = defineStore(store_name, {
.then(r => this.subscribeForTransactionReceipt(account, r as TransactionResponse));
}
} catch (error) {
const trxError = getAntelope().config.wrapError('antelope.evm.error_transfer_failed', error);
const trxError = getAntelope().config.transactionError('antelope.evm.error_transfer_failed', error);
getAntelope().config.transactionErrorHandler(trxError, funcname);
throw trxError;
} finally {
Expand All @@ -347,7 +347,7 @@ export const useBalancesStore = defineStore(store_name, {
.then(r => this.subscribeForTransactionReceipt(account, r as TransactionResponse));
}
} catch (error) {
const trxError = getAntelope().config.wrapError('antelope.evm.error_wrap_failed', error);
const trxError = getAntelope().config.transactionError('antelope.evm.error_wrap_failed', error);
getAntelope().config.transactionErrorHandler(trxError, funcname);
throw trxError;
} finally {
Expand All @@ -371,7 +371,7 @@ export const useBalancesStore = defineStore(store_name, {
.then(r => this.subscribeForTransactionReceipt(account, r as TransactionResponse));
}
} catch (error) {
const trxError = getAntelope().config.wrapError('antelope.evm.error_unwrap_failed', error);
const trxError = getAntelope().config.transactionError('antelope.evm.error_unwrap_failed', error);
getAntelope().config.transactionErrorHandler(trxError, funcname);
throw trxError;
} finally {
Expand Down Expand Up @@ -403,7 +403,7 @@ export const useBalancesStore = defineStore(store_name, {
});
} catch (error) {
console.error(error);
throw getAntelope().config.wrapError('antelope.evm.error_transfer_failed', error);
throw getAntelope().config.transactionError('antelope.evm.error_transfer_failed', error);
} finally {
useFeedbackStore().unsetLoading('transferNativeTokens');
}
Expand All @@ -413,7 +413,7 @@ export const useBalancesStore = defineStore(store_name, {
settings: EVMChainSettings,
account: EvmAccountModel,
token: TokenClass,
to: string,
to: addressString,
amount: BigNumber,
): Promise<EvmTransactionResponse | SendTransactionResult> {
this.trace('transferEVMTokens', settings, account, token, to, amount.toString());
Expand All @@ -423,7 +423,7 @@ export const useBalancesStore = defineStore(store_name, {
return result as EvmTransactionResponse | SendTransactionResult;
} catch (error) {
console.error(error);
throw getAntelope().config.wrapError('antelope.evm.error_transfer_failed', error);
throw getAntelope().config.transactionError('antelope.evm.error_transfer_failed', error);
} finally {
useFeedbackStore().unsetLoading('transferEVMTokens');
}
Expand Down
63 changes: 36 additions & 27 deletions src/antelope/stores/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { defineStore } from 'pinia';
import {
CURRENT_CONTEXT,
useAccountStore,
useEVMStore,
useContractStore,
useFeedbackStore,
} from 'src/antelope';

Expand Down Expand Up @@ -149,14 +149,19 @@ export const useChainStore = defineStore(store_name, {
},
async updateSettings(label: string): Promise<void> {
this.trace('updateSettings', label);
const settings = this.getChain(label).settings as EVMChainSettings;
settings.init().then(() => {
this.trace('updateSettings', label, '-> onChainIndexerReady.next()');
getAntelope().events.onChainIndexerReady.next({ label, ready: true });
}).catch((error) => {
try {
const settings = this.getChain(label).settings as EVMChainSettings;
settings.init().then(() => {
this.trace('updateSettings', label, '-> onChainIndexerReady.next()');
getAntelope().events.onChainIndexerReady.next({ label, ready: true });
}).catch((error) => {
console.error(error);
throw new Error('antelope.chain.error_settings_not_found');
});
} catch (error) {
console.error(error);
throw new Error('antelope.chain.error_settings');
});
throw new Error('antelope.chain.error_settings_not_found');
}
},
async updateApy(label: string): Promise<void> {
useFeedbackStore().setLoading('updateApy');
Expand All @@ -175,7 +180,6 @@ export const useChainStore = defineStore(store_name, {
// first we need the contract instance to be able to execute queries
this.trace('actualUpdateStakedRatio', label);
useFeedbackStore().setLoading('actualUpdateStakedRatio');
const evm = useEVMStore();
const chain_settings = useChainStore().getChain(label).settings as EVMChainSettings;
const sysToken = chain_settings.getSystemToken();
const stkToken = chain_settings.getStakedSystemToken();
Expand All @@ -185,7 +189,7 @@ export const useChainStore = defineStore(store_name, {
this.trace('actualUpdateStakedRatio', label, '-> no authenticator');
throw new AntelopeError('antelope.chain.error_no_default_authenticator');
}
const contract = await evm.getContract(authenticator, stkToken.address, stkToken.type);
const contract = await useContractStore().getContract(label, stkToken.address, stkToken.type);
if (!contract) {
useFeedbackStore().unsetLoading('actualUpdateStakedRatio');
this.trace('actualUpdateStakedRatio', label, '-> no contract');
Expand All @@ -194,33 +198,38 @@ export const useChainStore = defineStore(store_name, {
const contractInstance = await contract.getContractInstance();
// Now we preview a deposit of 1 SYS to get the ratio
const oneSys = ethers.utils.parseUnits('1.0', sysToken.decimals);
const stakedRatio:ethers.BigNumber = await contractInstance.previewDeposit(oneSys);
const stakedRatio = await contractInstance.previewDeposit(oneSys);
const unstakedRatio:ethers.BigNumber = await contractInstance.previewRedeem(oneSys);

// Finally we update the store
this.setStakedRatio(label, stakedRatio);
this.setUnstakedRatio(label, unstakedRatio);
useFeedbackStore().unsetLoading('actualUpdateStakedRatio');
},
async updateStakedRatio(label: string): Promise<void> {
this.trace('updateStakedRatio', label);
const accountModel = useAccountStore().getAccount(label);
if (accountModel && accountModel.account) {
// if the account is already logged, we can update the staked ratio
return this.actualUpdateStakedRatio(label);
} else {
// if the account is not logged, we need to wait for the login and then update the staked ratio
return new Promise((resolve) => {
const sub = getAntelope().events.onAccountChanged.subscribe((result) => {
if (result.label === label) {
sub.unsubscribe();
if (result.account) {
// we need the user to be logged because the way of getting the staked ratio is by
// executing an action from contract and that internally attempts retrieve the account from the provided signer
resolve(this.actualUpdateStakedRatio(label));
try {
if (accountModel && accountModel.account) {
// if the account is already logged, we can update the staked ratio
return this.actualUpdateStakedRatio(label);
} else {
// if the account is not logged, we need to wait for the login and then update the staked ratio
return new Promise((resolve) => {
const sub = getAntelope().events.onAccountChanged.subscribe((result) => {
if (result.label === label) {
sub.unsubscribe();
if (result.account) {
// we need the user to be logged because the way of getting the staked ratio is by
// executing an action from contract and that internally attempts retrieve the account from the provided signer
resolve(this.actualUpdateStakedRatio(label));
}
}
}
});
});
});
}
} catch (error) {
console.error(error);
throw new Error('antelope.chain.error_staked_ratio');
}
},
async updateGasPrice(label: string): Promise<void> {
Expand Down
Loading

0 comments on commit 7b2cd28

Please sign in to comment.