diff --git a/public/images/bk_maintenance.png b/public/images/bk_maintenance.png new file mode 100644 index 000000000..ba9e40756 Binary files /dev/null and b/public/images/bk_maintenance.png differ diff --git a/src/hooks/wallet/useAccountUnification.ts b/src/hooks/wallet/useAccountUnification.ts index 3ca9b244a..d58d12490 100644 --- a/src/hooks/wallet/useAccountUnification.ts +++ b/src/hooks/wallet/useAccountUnification.ts @@ -33,6 +33,7 @@ import { AbiItem } from 'web3-utils'; import { useNetworkInfo } from '../useNetworkInfo'; import { IAccountUnificationRepository, IIdentityRepository } from 'src/v2/repositories'; import { UnifiedAccount } from 'src/store/general/state'; +import { getRawEvmTransaction } from 'src/modules/evm'; const provider = get(window, 'ethereum') as any; @@ -280,19 +281,14 @@ export const useAccountUnification = () => { try { isSendingXc20Tokens.value = true; const from = selectedEvmAddress.value; - const [nonce, gasPrice] = await Promise.all([ - web3.value.eth.getTransactionCount(from), - web3.value.eth.getGasPrice(), - ]); - const multipliedGas = Math.round(Number(gasPrice) * 1.01); - const rawTx = { - nonce, - gasPrice: web3.value.utils.toHex(multipliedGas.toString()), + const rawTx = await getRawEvmTransaction( + web3.value, from, - to: evmPrecompiledContract.dispatch, - value: '0x0', - data: transferXc20CallData.value, - }; + evmPrecompiledContract.dispatch, + transferXc20CallData.value, + '0x0' + ); + const estimatedGas = await web3.value.eth.estimateGas(rawTx); await web3.value.eth .sendTransaction({ ...rawTx, gas: estimatedGas }) diff --git a/src/i18n/en-US/index.ts b/src/i18n/en-US/index.ts index 1fdaf3b89..4fe6d2b85 100644 --- a/src/i18n/en-US/index.ts +++ b/src/i18n/en-US/index.ts @@ -435,6 +435,11 @@ export default { warningLeaveMinAmount: 'Account must hold greater than {amount}{symbol} in transferrable when you stake.', }, + maintenance: { + switching: 'Switching to', + willBeBack: 'We will be back', + verySoon: 'very soon', + }, }, assets: { astarNativeAccount: 'Astar Native Account', diff --git a/src/layouts/DashboardLayout.vue b/src/layouts/DashboardLayout.vue index 51ee344b5..6e5428d84 100644 --- a/src/layouts/DashboardLayout.vue +++ b/src/layouts/DashboardLayout.vue @@ -64,6 +64,7 @@ export default defineComponent({ diff --git a/src/router/index.ts b/src/router/index.ts index 48cd8c9f6..5c925fc72 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -6,8 +6,8 @@ import { createWebHistory, } from 'vue-router'; import { StateInterface } from 'src/store'; -import routes from 'src/router/routes'; - +import routes, { Path } from 'src/router/routes'; +import { $api } from '../boot/api'; export { Path } from 'src/router/routes'; export { getHeaderName, buildTransferPageLink } from 'src/router/utils'; @@ -38,5 +38,22 @@ export default route(function (/* { store, ssrContext } */) { history: createHistory(process.env.MODE === 'ssr' ? void 0 : process.env.VUE_ROUTER_BASE), }); + // TODO - remove after the portal v3 is live. + Router.beforeEach((to, from, next) => { + // Prevent accessing to dApp staking pages if v3 is deployed to a node, but not supported by UI + const networksSupportV3 = ['development']; + const isStakingV3 = $api?.query.hasOwnProperty('dappStaking'); + const dontNavigateToDappStaking = + to.path.includes('/dapp-staking') && + !to.path.includes('/maintenance') && + !networksSupportV3.includes(to.params?.network?.toString()); + + if (isStakingV3 && dontNavigateToDappStaking) { + next({ path: Path.DappStaking + Path.Maintenance }); + } else { + next(); + } + }); + return Router; }); diff --git a/src/router/routes.ts b/src/router/routes.ts index b7365d826..a9ed3f071 100644 --- a/src/router/routes.ts +++ b/src/router/routes.ts @@ -13,6 +13,7 @@ import Dashboard from 'src/pages/Dashboard.vue'; import RegisterDapp from 'src/pages/RegisterDapp.vue'; import StakeManage from 'src/pages/StakeManage.vue'; import DappPage from 'src/pages/DappPage.vue'; +import MaintenanceMode from 'src/staking-v3/components/MaintenanceMode.vue'; import { RouteRecordRaw } from 'vue-router'; export { @@ -40,6 +41,7 @@ export enum Path { Transfer = '/transfer', XvmTransfer = '/xvm-transfer', Register = '/register', + Maintenance = '/maintenance', } const routes: RouteRecordRaw[] = [ @@ -68,6 +70,10 @@ const routes: RouteRecordRaw[] = [ path: Path.DappStaking + Path.Discover, redirect: networkParam + Path.DappStaking + Path.Discover, }, + { + path: Path.DappStaking + Path.Maintenance, + redirect: networkParam + Path.DappStaking + Path.Maintenance, + }, { path: '/store/discover-dapps', redirect: networkParam + Path.DappStaking + Path.Discover, @@ -156,6 +162,10 @@ const routes: RouteRecordRaw[] = [ path: 'register', component: RegisterDapp, }, + { + path: 'maintenance', + component: MaintenanceMode, + }, ], }, diff --git a/src/staking-v3/components/MaintenanceMode.vue b/src/staking-v3/components/MaintenanceMode.vue new file mode 100644 index 000000000..e52e7c4bd --- /dev/null +++ b/src/staking-v3/components/MaintenanceMode.vue @@ -0,0 +1,50 @@ + + + diff --git a/src/v2/services/implementations/MetamaskWalletService.ts b/src/v2/services/implementations/MetamaskWalletService.ts index cbf8430b6..cbdd561dd 100644 --- a/src/v2/services/implementations/MetamaskWalletService.ts +++ b/src/v2/services/implementations/MetamaskWalletService.ts @@ -17,6 +17,7 @@ import { import { WalletService } from 'src/v2/services/implementations'; import { Symbols } from 'src/v2/symbols'; import Web3 from 'web3'; +import { getRawEvmTransaction } from 'src/modules/evm'; @injectable() export class MetamaskWalletService extends WalletService implements IWalletService { @@ -122,21 +123,7 @@ export class MetamaskWalletService extends WalletService implements IWalletServi }: ParamSendEvmTransaction): Promise { try { const web3 = new Web3(this.provider as any); - const [nonce, gasPrice] = await Promise.all([ - web3.eth.getTransactionCount(from), - web3.eth.getGasPrice(), - ]); - - const multipliedGas = Math.round(Number(gasPrice) * 1.01); - const rawTx = { - nonce, - from, - to, - value: value ? value : '0x0', - data, - gasPrice: web3.utils.toHex(multipliedGas.toString()), - }; - + const rawTx = await getRawEvmTransaction(web3, from, to, data, value); const estimatedGas = await web3.eth.estimateGas(rawTx); const transactionHash = await web3.eth .sendTransaction({ ...rawTx, gas: estimatedGas }) diff --git a/src/v2/services/implementations/XcmEvmService.ts b/src/v2/services/implementations/XcmEvmService.ts index c0a1521fb..d84c66884 100644 --- a/src/v2/services/implementations/XcmEvmService.ts +++ b/src/v2/services/implementations/XcmEvmService.ts @@ -16,11 +16,11 @@ import { Chain, ethWalletChains } from 'src/v2/models'; import { IGasPriceProvider, IXcmEvmService, TransferParam } from 'src/v2/services'; import { Symbols } from 'src/v2/symbols'; import Web3 from 'web3'; -import { TransactionConfig } from 'web3-eth'; import { AbiItem } from 'web3-utils'; import { AlertMsg } from 'src/modules/toast'; import { getEvmExplorerUrl } from 'src/links'; import { evmPrecompiledContract } from 'src/modules/precompiled'; +import { getRawEvmTransaction } from 'src/modules/evm'; @injectable() export class XcmEvmService implements IXcmEvmService { @@ -73,31 +73,23 @@ export class XcmEvmService implements IXcmEvmService { const provider = getEvmProvider(this.currentWallet as any); const web3 = new Web3(provider as any); const contract = new web3.eth.Contract(ABI as AbiItem[], evmPrecompiledContract.xcm); - - const [nonce, gasPrice] = await Promise.all([ - web3.eth.getTransactionCount(senderAddress), - web3.eth.getGasPrice(), - ]); - const multipliedGas = Math.round(Number(gasPrice) * 1.01); - - const rawTx: TransactionConfig = { - nonce, - gasPrice: web3.utils.toHex(multipliedGas.toString()), - from: senderAddress, - to: evmPrecompiledContract.xcm, - value: '0x0', - data: contract.methods - .assets_withdraw( - assetIds, - assetAmounts, - recipientAccountId, - isRelay, - parachainId, - feeIndex - ) - .encodeABI(), - }; - + const data = contract.methods + .assets_withdraw( + assetIds, + assetAmounts, + recipientAccountId, + isRelay, + parachainId, + feeIndex + ) + .encodeABI(); + const rawTx = await getRawEvmTransaction( + web3, + senderAddress, + evmPrecompiledContract.xcm, + data, + '0x0' + ); const estimatedGas = await web3.eth.estimateGas(rawTx); await web3.eth .sendTransaction({ ...rawTx, gas: estimatedGas })