Skip to content

Commit

Permalink
Merge pull request #824 from telosnetwork/823-wallet-redirecting-to-t…
Browse files Browse the repository at this point in the history
…eloszero-mainnet-even-when-testnet-is-selected

Bugfix: Wallet redirecting to TelosZero mainnet even when testnet is selected
  • Loading branch information
rozzaswap authored Jul 25, 2024
2 parents d5723a0 + 7023df0 commit 253ca88
Show file tree
Hide file tree
Showing 36 changed files with 177 additions and 1,672 deletions.
19 changes: 1 addition & 18 deletions env.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,19 @@ const sharedEnv = {
IMGUR_CLIENT_ID: 'b6f46df9d1da9d9',
EVM_CONTRACT: 'eosio.evm',
PROJECT_ID: '2392473d6d98499c7138cd2d705a791f',
APP_NAME: 'Telos Web Wallet',
};

const TESTNET = {
...sharedEnv,
FUEL_RPC: '', // no Fuel support for Test-net yet
APP_NAME: 'Telos Web Wallet (testnet)',
NETWORK_HOST: 'testnet.telos.net',
NETWORK_CHAIN_ID:
'1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f',
TELOS_API_ENDPOINT: 'https://api-dev.telos.net/v1',
HYPERION_ENDPOINT: 'https://testnet.telos.net',
NETWORK_EXPLORER: 'https://explorer-test.telos.net',
CHAIN_NAME: 'telos-testnet',
OREID_APP_ID: 't_75a4d9233ec441d18c4221e92b379197',
OREID_APP_ID_NATIVE: 't_a61e9926d5204387a9ac113dfce7cbc5',
};

const MAINNET = {
...sharedEnv,
FUEL_RPC: 'https://telos.greymass.com',
APP_NAME: 'Telos Web Wallet',
NETWORK_HOST: 'mainnet.telos.net',
NETWORK_CHAIN_ID:
'4667b205c6838ef70ff7988f6e8257e8be0e1284a2f59699054a018f743b1d11',
TELOS_API_ENDPOINT: 'https://api.telos.net/v1',
HYPERION_ENDPOINT: 'https://mainnet.telos.net',
NETWORK_EXPLORER: 'https://explorer.telos.net',
CHAIN_NAME: 'telos',
OREID_APP_ID: 'p_e5b81fcc20a04339993b0cc80df7e3fd',
OREID_APP_ID_NATIVE: 'p_751f87258d5b40998b55c626d612fd4e',
};

const env = process.env.NETWORK === 'mainnet' ? MAINNET : TESTNET;
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
"mitt": "^3.0.0",
"node-polyfill-webpack-plugin": "^2.0.1",
"numeral": "^2.0.6",
"oreid-js": "^4.7.1",
"oreid-webpopup": "^2.4.0",
"pinia": "^2.0.33",
"ptokens": "^0.14.0",
"qrcanvas-vue": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion quasar.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = function(/* ctx */) {
// app boot file (/src/boot)
// --> boot files are part of "main.js"
// https://quasar.dev/quasar-cli/boot-files
boot: ['ual', 'i18n', 'fuel', 'api', 'errorHandling', 'helpers', 'mixin', 'emitter', 'telosApi', 'wagmi', 'antelope'],
boot: ['ual', 'i18n', 'fuel', 'api', 'errorHandling', 'helpers', 'mixin', 'emitter', 'wagmi', 'antelope'],

// https://quasar.dev/quasar-cli/quasar-conf-js#Property%3A-css
css: ['index.scss'],
Expand Down
5 changes: 3 additions & 2 deletions src/antelope/chains/NativeChainSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default abstract class NativeChainSettings implements ChainSettings {
const interval = setInterval(() => {
if (pendingRequests < MAX_REQUESTS_COUNT) {
pendingRequests++;
clearInterval(interval);
clearInterval(interval as unknown as number);
resolve(value);
}
}, INTERVAL_MS);
Expand Down Expand Up @@ -150,6 +150,7 @@ export default abstract class NativeChainSettings implements ChainSettings {
abstract getTheme(): Theme;
abstract getFiltersSupported(prop: string): boolean;
abstract trackAnalyticsEvent(eventName: string): void;
abstract getNftAccounts(): string[];

/**
* Retrieves the list of IDs for the important tokens.
Expand Down Expand Up @@ -228,7 +229,7 @@ export default abstract class NativeChainSettings implements ChainSettings {
if (amount > 0 && tk) {
balance = ethers.utils.parseUnits(toStringNumber(amount), tk.decimals);
}
const tokenBalance = new TokenBalance(tk, balance);
const tokenBalance = new TokenBalance(tk ? tk : { symbol:'', decimals:0 } as TokenClass, balance);
return tokenBalance;
},
// filtering by positive balances
Expand Down
5 changes: 5 additions & 0 deletions src/antelope/chains/native/eos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const FUEL_RPC_ENDPOINT = {
host: 'eos.greymass.com',
port: 443,
};
const NFT_ACCOUNTS = [] as string[];
const API_ENDPOINT = 'https://example.com';
const S3_PRODUCER_BUCKET = 'https://telos-producer-validation.s3.amazonaws.com';
const DISPLAY_MAP = true;
Expand All @@ -36,6 +37,10 @@ export default class EOS extends NativeChainSettings {
return NETWORK;
}

getNftAccounts(): string[] {
return NFT_ACCOUNTS;
}

getChainId(): string {
return CHAIN_ID;
}
Expand Down
5 changes: 5 additions & 0 deletions src/antelope/chains/native/jungle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const RPC_ENDPOINT = {
host: 'jungle.eosusa.news',
port: 443,
};
const NFT_ACCOUNTS = [] as string[];
const API_ENDPOINT = 'https://example.com';
const DISPLAY_MAP = true;
const THEME = {};
Expand All @@ -35,6 +36,10 @@ export default class TelosTestnet extends NativeChainSettings {
return NETWORK;
}

getNftAccounts(): string[] {
return NFT_ACCOUNTS;
}

getChainId(): string {
return CHAIN_ID;
}
Expand Down
5 changes: 5 additions & 0 deletions src/antelope/chains/native/telos-testnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const RPC_ENDPOINT = {
host: 'testnet.telos.net',
port: 443,
};
const NFT_ACCOUNTS = ['marbletessst'];
const API_ENDPOINT = 'https://api-dev.telos.net/v1';
const DISPLAY_MAP = false;
const THEME = {
Expand Down Expand Up @@ -55,6 +56,10 @@ export default class TelosTestnet extends NativeChainSettings {
return NETWORK;
}

getNftAccounts(): string[] {
return NFT_ACCOUNTS;
}

getChainId(): string {
return CHAIN_ID;
}
Expand Down
5 changes: 5 additions & 0 deletions src/antelope/chains/native/telos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const FUEL_RPC_ENDPOINT = {
host: 'telos.greymass.com',
port: 443,
};
const NFT_ACCOUNTS = ['tlos.tbond', 'marble.code'];
const API_ENDPOINT = 'https://api.telos.net/v1';
const S3_PRODUCER_BUCKET = 'https://telos-producer-validation.s3.amazonaws.com';
const DISPLAY_MAP = true;
Expand Down Expand Up @@ -58,6 +59,10 @@ export default class Telos extends NativeChainSettings {
return NETWORK;
}

getNftAccounts(): string[] {
return NFT_ACCOUNTS;
}

getChainId(): string {
return CHAIN_ID;
}
Expand Down
5 changes: 5 additions & 0 deletions src/antelope/chains/native/ux/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const RPC_ENDPOINT = {
host: 'ux.eosusa.io',
port: 443,
};
const NFT_ACCOUNTS = [] as string[];
const API_ENDPOINT = 'https://example.com';
const S3_PRODUCER_BUCKET = 'https://telos-producer-validation.s3.amazonaws.com';
const DISPLAY_MAP = true;
Expand All @@ -31,6 +32,10 @@ export default class UX extends NativeChainSettings {
return NETWORK;
}

getNftAccounts(): string[] {
return NFT_ACCOUNTS;
}

getChainId(): string {
return CHAIN_ID;
}
Expand Down
5 changes: 5 additions & 0 deletions src/antelope/chains/native/wax/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const RPC_ENDPOINT = {
host: 'wax.eosusa.io',
port: 443,
};
const NFT_ACCOUNTS = [] as string[];
const API_ENDPOINT = 'https://example.com';
const S3_PRODUCER_BUCKET = 'https://telos-producer-validation.s3.amazonaws.com';
const DISPLAY_MAP = true;
Expand All @@ -31,6 +32,10 @@ export default class EOS extends NativeChainSettings {
return NETWORK;
}

getNftAccounts(): string[] {
return NFT_ACCOUNTS;
}

getChainId(): string {
return CHAIN_ID;
}
Expand Down
13 changes: 1 addition & 12 deletions src/antelope/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { App, toRaw } from 'vue';
import { BehaviorSubject, Subject } from 'rxjs';
import { Store } from 'pinia';

import { AntelopeConfig, AntelopeDebug, chainNetworkNames } from 'src/antelope/config';
import { AntelopeConfig, AntelopeDebug } from 'src/antelope/config';
import installPinia from 'src/antelope/stores';

import { ChainModel } from 'src/antelope/stores/chain';
Expand Down Expand Up @@ -82,17 +82,6 @@ export class Antelope {
}
});

const chainStore = useChainStore();

if (!chainStore.currentChain) {
if (!process.env.CHAIN_NAME) {
console.error('No chain name specified in environment config; the application will not run correctly');
} else {
const network: string = chainNetworkNames[process.env.CHAIN_NAME];
chainStore.setChain(CURRENT_CONTEXT, network);
}
}

// Initializing store
stores.user.loadUsers();
}
Expand Down
3 changes: 1 addition & 2 deletions src/antelope/stores/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ export const useAccountStore = defineStore(store_name, {
authenticator,
} as NativeAccountModel;
this.setAccount(nativeAccount);

localStorage.setItem('network', network);
localStorage.setItem('account', account);
localStorage.setItem('isNative', 'true');
Expand Down Expand Up @@ -264,7 +263,7 @@ export const useAccountStore = defineStore(store_name, {
network,
});
} else {
const authenticator = getAntelope().wallets.getAuthenticator(autoLogin)?.newInstance(label);
const authenticator = getAntelope().wallets.getEVMAuthenticator(autoLogin)?.newInstance(label);
if (!authenticator) {
console.error(getAntelope().wallets);
throw new Error('antelope.account.error_auto_login');
Expand Down
1 change: 1 addition & 0 deletions src/antelope/stores/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ export const useChainStore = defineStore(store_name, {
if (network !== this.__chains[label]?.settings.getNetwork()) {
this.__chains[label] = chains[network];
this.trace('setChain', label, network, '--> void this.updateChainData(label);');
getAntelope().wallets.resetWeb3Provider();
void this.updateChainData(label);
getAntelope().events.onNetworkChanged.next(
{ label, chain: this.__chains[label] },
Expand Down
4 changes: 2 additions & 2 deletions src/antelope/stores/rex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export const useRexStore = defineStore(store_name, {
const deposits = await contract.depositsOf(address);
this.setDeposits(label, deposits);
} else {
console.error('updateDeposits', label, 'not supported for native chains yet');
this.trace('updateDeposits', label, 'not supported for native chains yet');
}
},
/**
Expand All @@ -239,7 +239,7 @@ export const useRexStore = defineStore(store_name, {
const balance = await contract.balanceOf(address);
this.setBalance(label, balance);
} else {
console.error('updateBalance', label, 'not supported for native chains yet');
this.trace('updateBalance', label, 'not supported for native chains yet');
}
},
/**
Expand Down
35 changes: 27 additions & 8 deletions src/antelope/wallets/AntelopeWallets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EVMAuthenticator } from 'src/antelope/wallets/authenticators/EVMAuthenticator';
import { CURRENT_CONTEXT, useChainStore } from 'src/antelope';
import { RpcEndpoint } from 'universal-authenticator-library';
import { Authenticator, RpcEndpoint } from 'universal-authenticator-library';
import { ethers } from 'ethers';
import EVMChainSettings from 'src/antelope/chains/EVMChainSettings';
import { AntelopeError } from 'src/antelope/types';
Expand All @@ -11,7 +11,8 @@ const name = 'AntelopeWallets';
export class AntelopeWallets {

private trace: AntelopeDebugTraceType;
private authenticators: Map<string, EVMAuthenticator> = new Map();
private evmAuthenticators: Map<string, EVMAuthenticator> = new Map();
private zeroAuthenticators: Map<string, Authenticator> = new Map();
private web3Provider: ethers.providers.Web3Provider | null = null;
private web3ProviderInitializationPromise: Promise<ethers.providers.Web3Provider> | null = null;

Expand All @@ -21,18 +22,36 @@ export class AntelopeWallets {

init() {
this.trace('init');


}

addEVMAuthenticator(authenticator: EVMAuthenticator) {
this.trace('addEVMAuthenticator', authenticator.getName(), authenticator);
this.authenticators.set(authenticator.getName(), authenticator);
this.evmAuthenticators.set(authenticator.getName(), authenticator);
}

addZeroAuthenticator(authenticator: Authenticator) {
this.trace('addZeroAuthenticator', authenticator.getName(), authenticator);
this.zeroAuthenticators.set(authenticator.getName(), authenticator);
}

getEVMAuthenticator(name: string) {
this.trace('getEVMAuthenticator', name);
return this.evmAuthenticators.get(name);
}

getZeroAuthenticator(name: string) {
this.trace('getZeroAuthenticator', name);
return this.zeroAuthenticators.get(name);
}

getEVMAuthenticators() {
this.trace('getEVMAuthenticators');
return Array.from(this.evmAuthenticators.values());
}

getAuthenticator(name: string) {
this.trace('getAuthenticator', name);
return this.authenticators.get(name);
getZeroAuthenticators() {
this.trace('getZeroAuthenticators');
return Array.from(this.zeroAuthenticators.values());
}

getChainSettings(label: string) {
Expand Down
Loading

0 comments on commit 253ca88

Please sign in to comment.