diff --git a/.eslintrc.js b/.eslintrc.js index d2f28d9c4..e87118a50 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -51,7 +51,6 @@ module.exports = { 'curly': 'error', 'brace-style': ['error', '1tbs', { 'allowSingleLine': false }], 'no-restricted-imports': ['error', { - 'patterns': ['.*'], // disallow relative imports }], 'no-return-assign': ['error', 'always'], 'no-param-reassign': 'error', diff --git a/env.js b/env.js index e503f8641..f3f9d3794 100644 --- a/env.js +++ b/env.js @@ -2,61 +2,24 @@ The environment variables ares set based on the single variable `MAINNET=true` (or absence thereof) in the root `.env` file. The following env vars are then assigned in `quasar.config.js`. -*/ +Cross chain support: most of the variables that were here have been moved to `src/config/chains` + +*/ const sharedEnv = { - NETWORK_PROTOCOL: 'https', - NETWORK_PORT: 443, - NETWORK_EVM_CONTRACT: 'eosio.evm', PROJECT_ID: '14ec76c44bae7d461fa0f5fd5f8a9da1', }; const TESTNET = { ...sharedEnv, APP_NAME: 'Teloscan (testnet)', - NETWORK_HOST: 'testnet.telos.net', - NETWORK_CHAIN_ID: - '1eaa0824707c8c16bd25145493bf062aecddfeb56c736f6ba6397f3195f33c9f', - NETWORK_EVM_RPC: 'https://testnet.telos.net/evm', - NETWORK_EVM_ENDPOINT: 'https://testnet.telos.net', - NETWORK_EVM_CHAIN_ID: 41, - NETWORK_EVM_DISPLAY: 'Telos Testnet', NETWORK_EVM_NAME: 'telos-evm-testnet', - HYPERION_ENDPOINT: 'https://testnet.telos.net', - NETWORK_EXPLORER: 'https://explorer-test.telos.net', - TELOS_API_ENDPOINT: 'https://api-dev.telos.net/v1', //'http://localhost:9999/v1', //for local instance of api - INDEXER_API_ENDPOINT: 'https://api.testnet.teloscan.io/v1', - EXPORT_API_ENDPOINT: 'https://api.testnet.teloscan.io', - VERIFIED_CONTRACTS_BUCKET: 'verified-evm-contracts-testnet', - STAKED_TLOS_CONTRACT_ADDRESS: '0xa9991E4daA44922D00a78B6D986cDf628d46C4DD', - TELOS_ESCROW_CONTRACT_ADDRESS: '0x7E9cF9fBc881652B05BB8F26298fFAB538163b6f', - MULTICALL_CONTRACT_ADDRESS: '0x39b0CF441E616e4e21a5f7b37c9CE0Ca750bd05B', - OREID_APP_ID: 't_1e0417d2456e401893ec106e5e4c6314', - OREID_APP_ID_NATIVE: 't_a61e9926d5204387a9ac113dfce7cbc5', }; const MAINNET = { ...sharedEnv, APP_NAME: 'Teloscan', - NETWORK_HOST: 'mainnet.telos.net', - NETWORK_CHAIN_ID: - '4667b205c6838ef70ff7988f6e8257e8be0e1284a2f59699054a018f743b1d11', - NETWORK_EVM_RPC: 'https://mainnet.telos.net/evm', - NETWORK_EVM_ENDPOINT: 'https://mainnet.telos.net', - NETWORK_EVM_CHAIN_ID: 40, - NETWORK_EVM_DISPLAY: 'Telos', NETWORK_EVM_NAME: 'telos-evm', - HYPERION_ENDPOINT: 'https://mainnet.telos.net', - NETWORK_EXPLORER: 'https://explorer.telos.net', - TELOS_API_ENDPOINT: 'https://api.telos.net/v1', //'http://localhost:9999/v1', //for local instance of api - INDEXER_API_ENDPOINT: 'https://api.teloscan.io/v1', - EXPORT_API_ENDPOINT: 'https://api.teloscan.io', - VERIFIED_CONTRACTS_BUCKET: 'verified-evm-contracts', - STAKED_TLOS_CONTRACT_ADDRESS: '0xB4B01216a5Bc8F1C8A33CD990A1239030E60C905', - TELOS_ESCROW_CONTRACT_ADDRESS: '0x95F5713A1422Aa3FBD3DCB8D553945C128ee3855', - MULTICALL_CONTRACT_ADDRESS: '0xdDCbf776dF3dE60163066A5ddDF2277cB445E0F3', - OREID_APP_ID: 'p_b5cfbadeb17a44bdaf01e73b3120d202', - OREID_APP_ID_NATIVE: 'p_751f87258d5b40998b55c626d612fd4e', }; const env = process.env.NETWORK === 'mainnet' ? MAINNET : TESTNET; diff --git a/src/assets/telos-new-logo--dark.png b/public/assets/telos-new-logo--dark.png similarity index 100% rename from src/assets/telos-new-logo--dark.png rename to public/assets/telos-new-logo--dark.png diff --git a/src/assets/telos-new-logo.png b/public/assets/telos-new-logo.png similarity index 100% rename from src/assets/telos-new-logo.png rename to public/assets/telos-new-logo.png diff --git a/public/assets/telos-testnet-logo--dark.png b/public/assets/telos-testnet-logo--dark.png new file mode 100644 index 000000000..ff8b8dbb6 Binary files /dev/null and b/public/assets/telos-testnet-logo--dark.png differ diff --git a/public/assets/telos-testnet-logo.png b/public/assets/telos-testnet-logo.png new file mode 100644 index 000000000..18fe32da9 Binary files /dev/null and b/public/assets/telos-testnet-logo.png differ diff --git a/quasar.conf.js b/quasar.conf.js index df0aa4be3..414e6f968 100644 --- a/quasar.conf.js +++ b/quasar.conf.js @@ -32,12 +32,8 @@ module.exports = function(/* ctx */) { // --> boot files are part of "main.js" // https://quasar.dev/quasar-cli/boot-files boot: [ - 'ual', - 'hyperion', 'i18n', - 'api', 'errorHandling', - 'telosApi', 'evm', 'q-component-defaults', 'antelope', diff --git a/src/App.vue b/src/App.vue index 5829078c8..50a8e7143 100644 --- a/src/App.vue +++ b/src/App.vue @@ -5,10 +5,8 @@ import { useI18n } from 'vue-i18n'; import { useQuasar } from 'quasar'; import moment from 'moment'; -import { getAntelope, useChainStore } from 'src/antelope'; -import { TELOS_NETWORK_NAMES } from 'src/antelope/mocks/chain-constants'; -import { indexerApi } from 'src/boot/telosApi'; -import { ual } from 'src/boot/ual'; +import { getAntelope, useChainStore } from 'src/core'; +import { TELOS_NETWORK_NAMES } from 'src/core/mocks/chain-constants'; import { providerManager } from 'src/boot/evm'; const $store = useStore(); @@ -28,8 +26,8 @@ onMounted(async () => { script.defer = true; document.body.appendChild(script); } - - const health = await indexerApi.get('/health'); + const indexerApi = useChainStore().currentChain.settings.getIndexerApi(); + const health = await indexerApi.get('/v1/health'); if (health.data?.secondsBehind > 3) { let behindBy = moment(health.data.secondsBehind * 1000).utc().format('HH:mm:ss'); @@ -63,7 +61,7 @@ onMounted(async () => { return; } const loginObj = JSON.parse(loginData); - const wallet = ual.getAuthenticators().availableAuthenticators.find(a => a.getName() === loginObj.provider); + const wallet = getAntelope().config.authenticatorsGetter().find(a => a.getName() === loginObj.provider); wallet?.logout(); } $store.commit('login/setLogin', {}); diff --git a/src/antelope/index.ts b/src/antelope/index.ts deleted file mode 100644 index a1cfac13e..000000000 --- a/src/antelope/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export * from 'src/antelope/mocks/AccountStore'; -export * from 'src/antelope/mocks/AntelopeConfig'; -export * from 'src/antelope/mocks/ChainStore'; -export * from 'src/antelope/mocks/ContractStore'; -export * from 'src/antelope/mocks/EVMStore'; -export * from 'src/antelope/mocks/FeedbackStore'; -export * from 'src/antelope/mocks/PlatformStore'; diff --git a/src/antelope/mocks/ChainStore.ts b/src/antelope/mocks/ChainStore.ts deleted file mode 100644 index 2afe7b82d..000000000 --- a/src/antelope/mocks/ChainStore.ts +++ /dev/null @@ -1,95 +0,0 @@ -/* eslint-disable no-unused-vars */ -/* eslint-disable @typescript-eslint/no-unused-vars */ -// Mocking ChainStore ----------------------------------- -declare const fathom: { trackEvent: (eventName: string) => void }; - -import { RpcEndpoint } from 'universal-authenticator-library'; -import { NativeCurrencyAddress, TokenClass } from 'src/antelope/types'; - -export interface EVMChainSettings { - getStakedSystemToken(): TokenClass; - getWrappedSystemToken: () => TokenClass; - getChainId: () => string; - getDisplay: () => string; - trackAnalyticsEvent: (name: string) => void; - getRPCEndpoint: () => RpcEndpoint; - getEscrowContractAddress: () => string; - getNetwork: () => string; - getSystemToken: () => TokenClass; - getExplorerUrl: () => string; - getSmallLogoPath: () => string; - getLargeLogoPath: () => string; -} - -const settings = { - getChainId: () => process.env.NETWORK_EVM_CHAIN_ID, - getDisplay: () => process.env.NETWORK_EVM_DISPLAY, - trackAnalyticsEvent(eventName: string): void { - if (typeof fathom === 'undefined') { - console.warn(`Failed to track event with name ${eventName}: Fathom Analytics not loaded`); - return; - } - - fathom.trackEvent(eventName); - }, - getRPCEndpoint: () => { - // extract the url parts - const regex = /^(https?):\/\/([^:/]+)(?::(\d+))?(\/.*)?$/; - const match = (process.env.NETWORK_EVM_RPC as string).match(regex); - if (!match) { - throw new Error('Invalid RPC endpoint'); - } - // We destructure the result of the match to get each component - const [, protocol, host, port, path] = match; - return { - protocol, - host, - port: port ? parseInt(port, 10) : 443, - path: path || '/', - }; - }, - getEscrowContractAddress: () => process.env.TELOS_ESCROW_CONTRACT_ADDRESS, - getStakedSystemToken: () => ({ - address: process.env.STAKED_TLOS_CONTRACT_ADDRESS, - decimals: 18, - symbol: 'STLOS', - } as TokenClass), - getWrappedSystemToken: () => ({ - address: process.env.WRAPPED_TLOS_CONTRACT_ADDRESS, - decimals: 18, - symbol: 'WTLOS', - } as TokenClass), - getSystemToken: () => ({ - name: 'Telos', - address: NativeCurrencyAddress, - decimals: 18, - symbol: 'TLOS', - } as TokenClass), - getNetwork: () => process.env.NETWORK_EVM_NAME, - getExplorerUrl: () => window.location.origin, - getSmallLogoPath: () => 'small-icon-url', - getLargeLogoPath: () => 'large-icon-url', -} as EVMChainSettings; - -const currentChain = { - settings, -}; - -const loggedChain = { - settings, -}; - -const loggedEvmChain = { - settings, -}; - -const ChainStore = { - currentChain, - loggedChain, - loggedEvmChain, - getNetworkSettings: (network: string) => settings, - getChain: (label: string) => currentChain, - setChain: (context: string, network: string) => void 0, -}; - -export const useChainStore = () => ChainStore; diff --git a/src/antelope/mocks/index.ts b/src/antelope/mocks/index.ts deleted file mode 100644 index a9ab5b7e7..000000000 --- a/src/antelope/mocks/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -export * from 'src/antelope/mocks/FeedbackStore'; -export * from 'src/antelope/mocks/AccountStore'; -export * from 'src/antelope/mocks/AntelopeConfig'; -export * from 'src/antelope/mocks/ChainStore'; -export * from 'src/antelope/mocks/ContractStore'; -export * from 'src/antelope/mocks/EVMStore'; -export * from 'src/antelope/mocks/PlatformStore'; - -export const CURRENT_CONTEXT = 'current'; diff --git a/src/antelope/types/Theme.ts b/src/antelope/types/Theme.ts deleted file mode 100644 index dfe49cefd..000000000 --- a/src/antelope/types/Theme.ts +++ /dev/null @@ -1,17 +0,0 @@ -export interface Theme { - primary?: string; - secondary?: string; - accent?: string; - dark?: string; - positive?: string; - negative?: string; - info?: string; - warning?: string; - 'color-map'?: string; - 'color-primary-gradient'?: string; - 'color-secondary-gradient'?: string; - 'color-tertiary-gradient'?: string; - 'color-progress-gradient'?: string; - 'color-producer-card-background'?: string; - 'color-select-box-background'?: string; -} diff --git a/src/antelope/types/index.ts b/src/antelope/types/index.ts deleted file mode 100644 index 9c121127f..000000000 --- a/src/antelope/types/index.ts +++ /dev/null @@ -1,33 +0,0 @@ -// interfaces for antelope -export * from 'src/antelope/types/ABIv1'; -export * from 'src/antelope/types/Actions'; -export * from 'src/antelope/types/AntelopeError'; -export * from 'src/antelope/types/Api'; -export * from 'src/antelope/types/ChainInfo'; -export * from 'src/antelope/types/ChainSettings'; -export * from 'src/antelope/types/EvmBlockData'; -export * from 'src/antelope/types/EvmContractData'; -export * from 'src/antelope/types/EvmLog'; -export * from 'src/antelope/types/EvmRexDeposit'; -export * from 'src/antelope/types/EvmTransaction'; -export * from 'src/antelope/types/ExceptionError'; -export * from 'src/antelope/types/Filters'; -export * from 'src/antelope/types/IndexerTypes'; -export * from 'src/antelope/types/KeyAccounts'; -export * from 'src/antelope/types/Basic'; -export * from 'src/antelope/types/NFTClass'; -export * from 'src/antelope/types/OpenSeaTypes'; -export * from 'src/antelope/types/PriceData'; -export * from 'src/antelope/types/Proposals'; -export * from 'src/antelope/types/Producers'; -export * from 'src/antelope/types/Providers'; -export * from 'src/antelope/types/Theme'; -export * from 'src/antelope/types/TokenClass'; -export * from 'src/antelope/types/TransactionV1'; - - -// classes for antelope -export * from 'src/antelope/types/AntelopeError'; - -// interfaces for antelope evm-abi -export * from 'src/antelope/wallets/utils/abi'; diff --git a/src/antelope/wallets/index.ts b/src/antelope/wallets/index.ts deleted file mode 100644 index 07b7d65ca..000000000 --- a/src/antelope/wallets/index.ts +++ /dev/null @@ -1,9 +0,0 @@ - -export * from 'src/antelope/wallets/authenticators/EVMAuthenticator'; -export * from 'src/antelope/wallets/authenticators/OreIdAuth'; -export * from 'src/antelope/wallets/authenticators/InjectedProviderAuth'; -export * from 'src/antelope/wallets/authenticators/MetamaskAuth'; -export * from 'src/antelope/wallets/authenticators/SafePalAuth'; -export * from 'src/antelope/wallets/authenticators/WalletConnectAuth'; -export * from 'src/antelope/wallets/authenticators/BraveAuth'; -export * from 'src/antelope/mocks'; diff --git a/src/antelope/wallets/utils/abi/signature/index.ts b/src/antelope/wallets/utils/abi/signature/index.ts deleted file mode 100644 index 88a3fc857..000000000 --- a/src/antelope/wallets/utils/abi/signature/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from 'src/antelope/wallets/utils/abi/signature/events_signatures'; -export * from 'src/antelope/wallets/utils/abi/signature/functions_signatures'; -export * from 'src/antelope/wallets/utils/abi/signature/transfer_signatures'; diff --git a/src/assets/tokens/telos.png b/src/assets/tokens/telos.png new file mode 100644 index 000000000..2be9c2c7c Binary files /dev/null and b/src/assets/tokens/telos.png differ diff --git a/src/boot/antelope.ts b/src/boot/antelope.ts index 415b5528a..b45dbde81 100644 --- a/src/boot/antelope.ts +++ b/src/boot/antelope.ts @@ -1,9 +1,21 @@ import { boot } from 'quasar/wrappers'; -import { initAntelope } from 'src/antelope/wallets/init'; - +import { initAntelope } from 'src/core/wallets/init'; +import { evmSettings, useChainStore } from 'src/core'; export default boot(({ app }) => { initAntelope(app); + + const defaultNetwork = Object.keys(evmSettings)[0]; + let network = new URLSearchParams(window.location.search).get('network'); + if (network) { + const exists = Object.keys(evmSettings).some(key => evmSettings[key].getNetwork() === network); + if (!exists) { + network = defaultNetwork; + } + } else { + network = defaultNetwork; + } + useChainStore().setChain('not-used', network); }); diff --git a/src/boot/antelopeApi.js b/src/boot/antelopeApi.js deleted file mode 100644 index e90dc7d37..000000000 --- a/src/boot/antelopeApi.js +++ /dev/null @@ -1,71 +0,0 @@ -import { boot } from 'quasar/wrappers'; -import { Api, JsonRpc } from 'eosjs'; - -const signTransaction = async function(actions) { - actions.forEach((action) => { - if (!action.authorization || !action.authorization.length) { - action.authorization = [ - { - actor: this.state.account.accountName, - permission: 'active', - }, - ]; - } - }); - let transaction = null; - try { - if (this.$type === 'ual') { - transaction = await this.$ualUser.signTransaction( - { - actions, - }, - { - blocksBehind: 3, - expireSeconds: 30, - }, - ); - } - } catch (e) { - console.error(actions, e.cause.message); - throw e.cause.message; - } - return transaction; -}; - -const getRpc = function () { - return this.$type === 'ual' ? this.$ualUser.rpc : this.$defaultApi.rpc; -}; - -const getTableRows = async function(options) { - const rpc = this.$antelopeApi.getRpc(); - return await rpc.get_table_rows({ - json: true, - ...options, - }); -}; - -const getAccount = async function (accountName) { - const rpc = this.$antelopeApi.getRpc(); - return await rpc.get_account(accountName); -}; - -export default boot(async ({ app, store }) => { - store.$isAntelopeCapable = app.config.globalProperties.isAntelopeCapable = false; - if(process.env.NETWORK_PROTOCOL && process.env.NETWORK_HOST){ - const rpc = new JsonRpc( - `${process.env.NETWORK_PROTOCOL}://${process.env.NETWORK_HOST}:${process.env.NETWORK_PORT}`, - ); - store.$defaultApi = new Api({ - rpc, - textDecoder: new TextDecoder(), - textEncoder: new TextEncoder(), - }); - store.$isAntelopeCapable = app.config.globalProperties.isAntelopeCapable = true; - } - store.$antelopeApi = { - signTransaction: signTransaction.bind(store), - getTableRows: getTableRows.bind(store), - getAccount: getAccount.bind(store), - getRpc: getRpc.bind(store), - }; -}); diff --git a/src/boot/api.js b/src/boot/api.js deleted file mode 100644 index 66ffe3a11..000000000 --- a/src/boot/api.js +++ /dev/null @@ -1,69 +0,0 @@ -import { boot } from 'quasar/wrappers'; -import { Api, JsonRpc } from 'eosjs'; - -const signTransaction = async function(actions) { - actions.forEach((action) => { - if (!action.authorization || !action.authorization.length) { - action.authorization = [ - { - actor: this.state.account.accountName, - permission: 'active', - }, - ]; - } - }); - let transaction = null; - try { - if (this.$type === 'ual') { - transaction = await this.$ualUser.signTransaction( - { - actions, - }, - { - blocksBehind: 3, - expireSeconds: 30, - }, - ); - } - } catch (e) { - console.debug(actions, e.cause.message); - throw e.cause.message; - } - return transaction; -}; - -const getRpc = function () { - return this.$type === 'ual' ? this.$ualUser.rpc : this.$defaultApi.rpc; -}; - -const getTableRows = async function(options) { - const rpc = this.$api.getRpc(); - return await rpc.get_table_rows({ - json: true, - ...options, - }); -}; - -const getAccount = async function (accountName) { - const rpc = this.$api.getRpc(); - return await rpc.get_account(accountName); -}; - -export default boot(async ({ store }) => { - const rpc = new JsonRpc( - `${process.env.NETWORK_PROTOCOL}://${process.env.NETWORK_HOST}:${process.env.NETWORK_PORT}`, - ); - store['$defaultApi'] = new Api({ - rpc, - textDecoder: new TextDecoder(), - textEncoder: new TextEncoder(), - }); - - store['$api'] = { - signTransaction: signTransaction.bind(store), - getTableRows: getTableRows.bind(store), - getAccount: getAccount.bind(store), - getRpc: getRpc.bind(store), - }; - -}); diff --git a/src/boot/evm.js b/src/boot/evm.js index 9ebb6557e..f19d51cbb 100644 --- a/src/boot/evm.js +++ b/src/boot/evm.js @@ -1,17 +1,6 @@ import { boot } from 'quasar/wrappers'; -import { TelosEvmApi } from '@telosnetwork/telosevm-js'; -import fetch from 'node-fetch'; -import axios from 'axios'; import { ethers } from 'ethers'; - -const evm = new TelosEvmApi({ - endpoint: process.env.NETWORK_EVM_ENDPOINT, - chainId: parseInt(process.env.NETWORK_EVM_CHAIN_ID), - ethPrivateKeys: [], - telosContract: process.env.NETWORK_EVM_CONTRACT, - telosPrivateKeys: [], - fetch, -}); +import { useChainStore } from 'src/core'; // This is kinda bad, but if you try to store a web3 provider in the store, it has a call stack size exception, // and if you freeze the provider before putting in the store so the call stack error goes away, you break @@ -27,7 +16,7 @@ class ProviderManager { getEthersProvider() { return new ethers.providers.Web3Provider( - providerContainer.provider, parseInt(process.env.NETWORK_EVM_CHAIN_ID, 10), + providerContainer.provider, parseInt(useChainStore().currentChain.settings.getChainId(), 10), ); } @@ -36,16 +25,10 @@ class ProviderManager { } } -const hyperion = axios.create({ - baseURL: process.env.NETWORK_EVM_ENDPOINT, -}); - const providerManager = new ProviderManager(); export default boot(({ app, store }) => { store.$providerManager = app.config.globalProperties.$providerManager = providerManager; - store.$evm = app.config.globalProperties.$evm = evm; - store.$evmEndpoint = app.config.globalProperties.$evmEndpoint = hyperion; }); -export { evm, providerManager }; +export { providerManager }; diff --git a/src/boot/hyperion.js b/src/boot/hyperion.js deleted file mode 100644 index 76bae4d9a..000000000 --- a/src/boot/hyperion.js +++ /dev/null @@ -1,13 +0,0 @@ -import { boot } from 'quasar/wrappers'; -import axios from 'axios'; - -const hyperion = axios.create({ - baseURL: process.env.HYPERION_ENDPOINT, -}); - -export default boot(({ app, store }) => { - app.config.globalProperties.$hyperion = hyperion; - store.$hyperion = hyperion; -}); - -export { hyperion }; diff --git a/src/boot/telosApi.js b/src/boot/telosApi.js deleted file mode 100644 index 88724a0f4..000000000 --- a/src/boot/telosApi.js +++ /dev/null @@ -1,50 +0,0 @@ -import { boot } from 'quasar/wrappers'; -import axios from 'axios'; -import ContractManager from 'src/lib/contract/ContractManager'; -import FragmentParser from 'src/lib/contract/FragmentParser'; -import { markRaw } from 'vue'; - -const telosApi = axios.create({ - baseURL: process.env.TELOS_API_ENDPOINT, -}); -const indexerApi = axios.create({ - baseURL: process.env.INDEXER_API_ENDPOINT, -}); -const exportApi = axios.create({ - baseURL: process.env.EXPORT_API_ENDPOINT, -}); -const hyperion = axios.create({ - baseURL: process.env.NETWORK_EVM_ENDPOINT, -}); - -const fragmentParser = new FragmentParser(hyperion); -let contractManager = new ContractManager(indexerApi, fragmentParser); - - -export default boot(({ app, store }) => { - app.config.globalProperties.$telosApi = telosApi; - app.config.globalProperties.$indexerApi = indexerApi; - app.config.globalProperties.$exportApi = exportApi; - app.config.globalProperties.$fragmentParser = fragmentParser; - store.$contractManager = app.config.globalProperties.$contractManager = markRaw(contractManager); - store.$indexerApi = indexerApi; - store.$exportApi = exportApi; - // Intercept API answer to set contracts & abi in cache directly - indexerApi.interceptors.response.use(function (response) { - if(response.data?.abi?.length > 0){ - for (const [key, value] of Object.entries(response.data.abi)) { - app.config.globalProperties.$contractManager.parser.addFunctionInterface(key, value); - app.config.globalProperties.$fragmentParser.addFunctionInterface(key, value); - } - } - if(response.data?.contracts){ - app.config.globalProperties.$contractManager.addContractsToCache(response.data.contracts); - } - return response; - }, function (error) { - return Promise.reject(error); - }); - -}); - -export { telosApi, indexerApi, exportApi, contractManager, fragmentParser }; diff --git a/src/boot/ual.js b/src/boot/ual.js deleted file mode 100644 index 671ed4d49..000000000 --- a/src/boot/ual.js +++ /dev/null @@ -1,29 +0,0 @@ -import { boot } from 'quasar/wrappers'; -import { UAL } from 'universal-authenticator-library'; -import { Wombat } from 'ual-wombat'; -import { Anchor } from 'ual-anchor'; - -const chain = { - chainId: process.env.NETWORK_CHAIN_ID, - rpcEndpoints: [ - { - protocol: process.env.NETWORK_PROTOCOL, - host: process.env.NETWORK_HOST, - port: process.env.NETWORK_PORT, - }, - ], -}; - -const authenticators = [ - new Anchor([chain], { appName: process.env.APP_NAME }), - new Wombat([chain], { appName: process.env.APP_NAME }), -]; - -const ual = new UAL([chain], 'ual', authenticators); - -export default boot(async({ app, store }) => { - store['$ual'] = ual; - app.config.globalProperties.$ual = ual; -}); - -export { ual }; diff --git a/src/components/AddressField.vue b/src/components/AddressField.vue index 211199ed7..9d9528e99 100644 --- a/src/components/AddressField.vue +++ b/src/components/AddressField.vue @@ -1,13 +1,12 @@ @@ -482,7 +444,7 @@ export default defineComponent({ - diff --git a/src/components/LoginModal.vue b/src/components/LoginModal.vue index ac40eb234..efcc624b4 100644 --- a/src/components/LoginModal.vue +++ b/src/components/LoginModal.vue @@ -5,7 +5,6 @@ import { useStore } from 'vuex'; import { useI18n } from 'vue-i18n'; import detectEthereumProvider from '@metamask/detect-provider'; import { Authenticator } from 'universal-authenticator-library'; -import { TelosEvmApi } from '@telosnetwork/telosevm-js'; import { LOGIN_EVM, @@ -22,9 +21,8 @@ import { getAntelope, useAccountStore, useChainStore, -} from 'src/antelope/mocks'; -import { ual } from 'src/boot/ual'; -import { evm, providerManager } from 'src/boot/evm'; +} from 'src/core/mocks'; +import { providerManager } from 'src/boot/evm'; const $q = useQuasar(); const store = useStore(); @@ -42,7 +40,7 @@ const browserSupportsMetaMask = ref(true); const isBraveBrowser = ref(false); const isIOSMobile = ref(false); -const authenticators = computed(() => ual.getAuthenticators().availableAuthenticators); +const authenticators = computed(() => getAntelope().config.authenticatorsGetter()); onMounted(async () => { await detectProvider(); @@ -111,9 +109,10 @@ async function ualLogin(wallet: Authenticator, account?: string) { if (users.length) { const account = users[0]; const accountName = await account.getAccountName(); - let evmAccount; + let evmAccount = ''; try { - evmAccount = await (evm as unknown as TelosEvmApi).telos.getEthAccountByTelosAccount(accountName); + const chain = useChainStore().currentChain; + evmAccount = await chain.settings.getEthAccountByNativeAccount(accountName); } catch (e) { $q.notify({ position: 'top', @@ -124,14 +123,14 @@ async function ualLogin(wallet: Authenticator, account?: string) { return; } setLogin({ - address: evmAccount.address, + address: evmAccount, nativeAccount: accountName, }); providerManager.setProvider(account); localStorage.setItem(LOGIN_DATA_KEY, JSON.stringify({ type: LOGIN_NATIVE, provider: wallet.getName(), - account: evmAccount.address, + account: evmAccount, })); } emit('hide'); diff --git a/src/components/MethodField.vue b/src/components/MethodField.vue index 235254f2d..505a98cf6 100644 --- a/src/components/MethodField.vue +++ b/src/components/MethodField.vue @@ -4,6 +4,7 @@ import { useI18n } from 'vue-i18n'; import { ZERO_ADDRESSES } from 'src/lib/utils'; import { useStore } from 'vuex'; +import { useChainStore } from 'src/core'; const { t: $t } = useI18n(); @@ -103,7 +104,9 @@ const setValues = async () => { nativeTooltipText.value = $t('pages.transactions.native_withdraw_tooltip'); methodName.value = $t('pages.transactions.withdraw_action_name'); } else if (!props.trx.parsedTransaction && props.trx.input === '0x' && propValue.value) { - methodName.value = $t('pages.transactions.transfer_tlos_action_name'); + methodName.value = $t('pages.transactions.transfer_tlos_action_name', { + symbol: useChainStore().currentChain.settings.getSystemToken().symbol, + }); } else if (!props.trx.parsedTransaction && props.trx.to === null) { methodName.value = $t('pages.transactions.contract_deployment'); } else if (props.trx.parsedTransaction) { diff --git a/src/components/NftItemField.vue b/src/components/NftItemField.vue index 5addbc695..671407973 100644 --- a/src/components/NftItemField.vue +++ b/src/components/NftItemField.vue @@ -1,8 +1,7 @@ + - + + + + + + diff --git a/src/components/Transaction/ERCTransferList.vue b/src/components/Transaction/ERCTransferList.vue index 00c8b4089..cd704b4e1 100644 --- a/src/components/Transaction/ERCTransferList.vue +++ b/src/components/Transaction/ERCTransferList.vue @@ -5,13 +5,13 @@ import { useI18n } from 'vue-i18n'; import { useQuasar } from 'quasar'; import { BigNumber } from 'ethers'; -import { EvmLogs } from 'src/antelope/types/EvmLog'; +import { EvmLogs } from 'src/core/types/EvmLog'; import AddressField from 'components/AddressField.vue'; import ValueField from 'components/ValueField.vue'; import { ERC721Transfer, ERC1155Transfer, ERC20Transfer, TokenBasicData } from 'src/types'; -import { contractManager } from 'src/boot/telosApi'; -import { TRANSFER_SIGNATURES } from 'src/antelope/types'; +import { TRANSFER_SIGNATURES } from 'src/core/types'; +import { useChainStore } from 'src/core'; const $q = useQuasar(); const { t: $t } = useI18n(); @@ -46,6 +46,8 @@ const loadTransfers = async () => { return; } + const contractManager = useChainStore().currentChain.settings.getContractManager(); + const logs = props.logs as EvmLogs; for (const log of logs) { diff --git a/src/components/Transaction/FragmentListElement.vue b/src/components/Transaction/FragmentListElement.vue index 2c9a72798..1f5e73578 100644 --- a/src/components/Transaction/FragmentListElement.vue +++ b/src/components/Transaction/FragmentListElement.vue @@ -5,6 +5,7 @@ import ParameterList from 'components/Transaction/ParameterList'; import AddressField from 'components/AddressField'; import { formatWei } from 'src/lib/utils'; import { BigNumber } from 'ethers'; +import { useChainStore } from 'src/core'; export default { name: 'FragmentListElement', @@ -88,6 +89,9 @@ export default { !this.fragment.name ); }, + systemSymbol(){ + return useChainStore().currentChain.settings.getSystemToken().symbol; + }, }, }; @@ -186,7 +190,7 @@ export default { {{ $t('components.transaction.value_uint256').toLowerCase() }}
- {{ fragment.value }} TLOS + {{ fragment.value }} {{ systemSymbol }}
diff --git a/src/components/Transaction/InternalTxns.vue b/src/components/Transaction/InternalTxns.vue index 509c1cb52..afc453efe 100644 --- a/src/components/Transaction/InternalTxns.vue +++ b/src/components/Transaction/InternalTxns.vue @@ -3,6 +3,7 @@ import VueJsonPretty from 'vue-json-pretty'; import 'vue-json-pretty/lib/styles.css'; import FragmentList from 'components/Transaction/FragmentList.vue'; import { getParsedInternalTransactions } from 'src/lib/transaction-utils'; +import { useChainStore } from 'src/core'; export default { @@ -25,7 +26,7 @@ export default { methods: { async getContract(address){ try { - return await this.$contractManager.getContract(address); + return await useChainStore().currentChain.settings.getContractManager().getContract(address); } catch (e) { console.error(`Failed to retrieve contract with address ${address}`); // Notify the user @@ -39,6 +40,10 @@ export default { }, async created() { this.loading = true; + if (!this.transaction) { + this.loading = false; + return; + } const { parsedItxs, itxs } = await getParsedInternalTransactions(this.transaction.hash, this.$t); this.parsedItxs = parsedItxs; this.itxs = itxs; diff --git a/src/components/Transaction/LogsViewer.vue b/src/components/Transaction/LogsViewer.vue index 0020d5e27..cf214c121 100644 --- a/src/components/Transaction/LogsViewer.vue +++ b/src/components/Transaction/LogsViewer.vue @@ -3,6 +3,7 @@ import VueJsonPretty from 'vue-json-pretty'; import 'vue-json-pretty/lib/styles.css'; import FragmentList from 'components/Transaction/FragmentList'; import { BigNumber } from 'ethers'; +import { useChainStore } from 'src/core'; export default { name: 'LogsViewer', @@ -13,7 +14,7 @@ export default { methods: { async getLogContract(log){ try { - return await this.$contractManager.getContract(log.address); + return await useChainStore().currentChain.settings.getContractManager().getContract(log.address); } catch (e) { console.error(`Failed to retrieve contract with address ${log.address}: ${e}`); this.$q.notify({ @@ -52,7 +53,7 @@ export default { let contract = await this.getLogContract(log); if (contract){ verified = (contract.isVerified()) ? verified + 1: verified; - let parsedLog = await this.$fragmentParser.parseLog(log, contract); + let parsedLog = await useChainStore().currentChain.settings.getFragmentParser().parseLog(log, contract); if(parsedLog){ this.parsedLogs.push(parsedLog); } else { diff --git a/src/components/Transaction/TLOSTransferList.vue b/src/components/Transaction/TLOSTransferList.vue index 450089210..7f78f559e 100644 --- a/src/components/Transaction/TLOSTransferList.vue +++ b/src/components/Transaction/TLOSTransferList.vue @@ -8,6 +8,7 @@ import ValueField from 'components/ValueField.vue'; import { EvmTransactionExtended } from 'src/types'; import { getParsedInternalTransactions } from 'src/lib/transaction-utils'; +import { useChainStore } from 'src/core'; const { t: $t } = useI18n(); @@ -51,13 +52,15 @@ const loadTransfers = async () => { tlos_transfers.value = result.parsedItxs .map((itx: any, i: number) => ({ ...itx, index: i })) - .filter((itx: any) => itx.name === $t('components.transaction.tlos_transfer')) + .filter((itx: any) => itx.name === $t('components.transaction.tlos_transfer', { + symbol: useChainStore().currentChain.settings.getSystemToken().symbol, + })) .map((itx: any) => ({ from: itx.from, to: itx.to, value: (result.itxs[itx.index] as {action:{value:string}}).action.value, token: { - symbol: 'TLOS', + symbol: useChainStore().currentChain.settings.getSystemToken().symbol, decimals: 18, }, })); diff --git a/src/components/TransactionAction.vue b/src/components/TransactionAction.vue index f6295f06c..70ba7db39 100644 --- a/src/components/TransactionAction.vue +++ b/src/components/TransactionAction.vue @@ -5,6 +5,7 @@ import { useI18n } from 'vue-i18n'; import MethodField from 'components/MethodField.vue'; import AddressField from 'components/AddressField.vue'; import ValueField from 'components/ValueField.vue'; +import { useChainStore } from 'src/core'; const { t: $t } = useI18n(); @@ -98,7 +99,7 @@ const setValues = async () => { to diff --git a/src/components/TransactionDialog.vue b/src/components/TransactionDialog.vue index 6c9c456ba..43a5c7f1c 100644 --- a/src/components/TransactionDialog.vue +++ b/src/components/TransactionDialog.vue @@ -3,10 +3,11 @@ import { computed, ref } from 'vue'; import { BigNumber } from 'ethers/lib/ethers'; import { useI18n } from 'vue-i18n'; -import { truncateAddress } from 'src/antelope/wallets/utils/text-utils'; +import { truncateAddress } from 'src/core/wallets/utils/text-utils'; import { WEI_PRECISION, ZERO_ADDRESSES, formatWei } from 'src/lib/utils'; import OutlineButton from 'src/components/OutlineButton.vue'; +import { useChainStore } from 'src/core'; const $i18n = useI18n(); const $t = $i18n.t; @@ -130,7 +131,7 @@ function formatTlos(value: string) {
{{ $t('pages.transactions.transaction_fee_label') }}: -

{{ totalGasFee }} TLOS

+

{{ totalGasFee }} {{ useChainStore().currentChain.settings.getSystemToken().symbol }}

{{ $t('pages.transactions.gas_info_label') }}: diff --git a/src/components/TransactionOverview.vue b/src/components/TransactionOverview.vue index 0023b475c..52a17da10 100644 --- a/src/components/TransactionOverview.vue +++ b/src/components/TransactionOverview.vue @@ -3,8 +3,6 @@ import { computed, onMounted, ref, toRaw, watch } from 'vue'; import { useI18n } from 'vue-i18n'; import { BlockData, EvmTransactionExtended } from 'src/types'; -import { WEI_PRECISION } from 'src/lib/utils'; -import { indexerApi } from 'src/boot/telosApi'; import AddressField from 'components/AddressField.vue'; import BlockField from 'components/BlockField.vue'; @@ -16,6 +14,7 @@ import TransactionField from 'components/TransactionField.vue'; import TransactionFeeField from 'components/TransactionFeeField.vue'; import ERCTransferList from 'components/Transaction/ERCTransferList.vue'; import TLOSTransferList from 'components/Transaction/TLOSTransferList.vue'; +import { useChainStore } from 'src/core'; import TransactionInputViewer from 'components/Transaction/TransactionInputViewer.vue'; import { DecodedTransactionInput, getParsedInternalTransactions } from 'src/lib/transaction-utils'; @@ -43,9 +42,10 @@ const showTLOSTransfers = ref(true); const moreDetailsHeight = ref(0); const loadBlockData = async () => { + const indexerApi = useChainStore().currentChain.settings.getIndexerApi(); try { if (blockNumber.value) { - const response = await indexerApi.get(`/block/${blockNumber.value}`); + const response = await indexerApi.get(`/v1/block/${blockNumber.value}`); blockData.value = response.data?.results?.[0] as BlockData; } } catch (error) { @@ -72,7 +72,6 @@ async function loadParsedInternalTransactions() { watch(() => props.trx, async (newTrx) => { if (newTrx) { - console.log('newTrx', newTrx); if (newTrx.to) { toAddress.value = newTrx.to; } else { @@ -352,11 +351,15 @@ onMounted(() => {
- {{ $t('components.transaction.tlos_transfers_tooltip') }} + {{ $t('components.transaction.tlos_transfers_tooltip', { + symbol: useChainStore().currentChain.settings.getSystemToken().symbol, + }) }}
-
{{ $t('components.transaction.tlos_transfers') }}
+
{{ $t('components.transaction.tlos_transfers', { + symbol: useChainStore().currentChain.settings.getSystemToken().symbol, + }) }}
{
diff --git a/src/components/TransactionTable.vue b/src/components/TransactionTable.vue index 07c468959..504102176 100644 --- a/src/components/TransactionTable.vue +++ b/src/components/TransactionTable.vue @@ -6,8 +6,6 @@ import { onBeforeMount, ref, watch } from 'vue'; import { useI18n } from 'vue-i18n'; import { getDirection } from 'src/lib/transaction-utils'; -import { contractManager, indexerApi } from 'src/boot/telosApi'; -import { WEI_PRECISION } from 'src/lib/utils'; import AddressField from 'components/AddressField.vue'; import BlockField from 'components/BlockField.vue'; @@ -18,8 +16,9 @@ import TransactionDialog from 'components/TransactionDialog.vue'; import TransactionField from 'components/TransactionField.vue'; import TransactionFeeField from 'components/TransactionFeeField.vue'; -import { Pagination, PaginationByKey } from 'src/types'; +import { PaginationByKey } from 'src/types'; import { useStore } from 'vuex'; +import { useChainStore } from 'src/core'; const $q = useQuasar(); const route = useRoute(); @@ -163,7 +162,7 @@ function setPagination(page: number, size: number, desc: boolean) { parseTransactions(); } -async function onPaginationChange(settings: { pagination: Pagination}) { +async function onPaginationChange(settings: { pagination: { sortBy: string; descending: boolean; page: number; rowsPerPage: number; } }) { const { page, rowsPerPage, descending } = settings.pagination; pagination.value.page = page; pagination.value.rowsPerPage = rowsPerPage; @@ -191,8 +190,8 @@ async function parseTransactions() { try { const path = await getPath(); - let response = await indexerApi.get(path); - totalRows.value = response.data.total_count; + let response = await useChainStore().currentChain.settings.getIndexerApi().get(path); + totalRows.value = response.data?.total_count; const results = response.data.results; pagination.value.rowsPerPage = rowsPerPage; @@ -213,13 +212,13 @@ async function parseTransactions() { continue; } - const contract = await contractManager.getContract(transaction.to); + const contract = await useChainStore().currentChain.settings.getContractManager().getContract(transaction.to); if (!contract) { continue; } - const parsedTransaction = await contractManager.parseContractTransaction( + const parsedTransaction = await useChainStore().currentChain.settings.getContractManager().parseContractTransaction( transaction, transaction.input, contract, true, ); if (parsedTransaction) { @@ -261,18 +260,20 @@ async function parseTransactions() { async function getPath() { const { page, rowsPerPage, descending } = pagination.value; - const limit = rowsPerPage === 0 ? 50 : Math.max(Math.min(rowsPerPage, props.initialPageSize), 10); + const limit = rowsPerPage; + console.assert(limit > 0, `Rows per page must be greater than 0, got ${limit}`); let path = ''; if (props.accountAddress) { - path = `address/${props.accountAddress}/transactions?limit=${limit}`; + path = `v1/address/${props.accountAddress}/transactions?limit=${limit}`; path += `&offset=${(page - 1) * rowsPerPage}`; } else { - path = `transactions?limit=${limit}`; - if (page === 1 || pagination.value.initialKey === 0) { - let response = await indexerApi.get('transactions?includePagination=true&limit=1'); - const firstKey = response.data.results[0]?.id || 0; - pagination.value.initialKey = firstKey + 1; + path = `v1/transactions?limit=${limit}`; + if (pagination.value.initialKey === 0) { + // in the case of the first query, we need to get the initial key + let response = await useChainStore().currentChain.settings.getIndexerApi().get('v1/transactions?includePagination=true&key=0'); + const next = response.data.next; + pagination.value.initialKey = next + 1; } let currentKey = pagination.value.initialKey - ((page - 1) * rowsPerPage); if (currentKey < 0) { @@ -330,7 +331,6 @@ onBeforeMount(() => { - { @@ -515,34 +515,11 @@ onBeforeMount(() => {