Skip to content

Commit

Permalink
Release hotfix to main (#1099)
Browse files Browse the repository at this point in the history
* Maintenance mode (#1090)

* Maintenance mode

* Cleanup

* Comment update

* Update dapp_promotions.json (#1095)

* EVM gas estimation fix (#1094)

* EVM gas estimation fix

* Refactoring

---------

Co-authored-by: Ahmet Öztürk <[email protected]>
  • Loading branch information
bobo-k2 and ahmetzturk authored Dec 22, 2023
1 parent 1d15689 commit e1cd87f
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 55 deletions.
Binary file added public/images/bk_maintenance.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 8 additions & 12 deletions src/hooks/wallet/useAccountUnification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 })
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/en-US/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/layouts/DashboardLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default defineComponent({

<style lang="scss" scoped>
.wrapper--components {
height: 100%;
@media (min-width: $lg) {
padding: 0 40px;
padding-top: 12px;
Expand Down
20 changes: 20 additions & 0 deletions src/modules/evm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Web3 from 'web3';
import { TransactionConfig } from 'web3-eth';

export const getRawEvmTransaction = async (
web3: Web3,
from: string,
to: string,
data: string,
value?: string
): Promise<TransactionConfig> => {
const nonce = await web3.eth.getTransactionCount(from);

return {
nonce,
from,
to,
value: value ? value : '0x0',
data,
};
};
8 changes: 8 additions & 0 deletions src/pages/DappStaking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export default defineComponent({
</script>

<style lang="scss">
.wrapper--dapp-staking {
height: 100%;
}
.dapps-staking-bg {
background-repeat: round;
position: fixed;
Expand All @@ -29,4 +33,8 @@ export default defineComponent({
height: 100vh;
opacity: 0.8;
}
.container--dapp-staking {
height: 100%;
}
</style>
21 changes: 19 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -38,5 +38,22 @@ export default route<StateInterface>(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;
});
10 changes: 10 additions & 0 deletions src/router/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -40,6 +41,7 @@ export enum Path {
Transfer = '/transfer',
XvmTransfer = '/xvm-transfer',
Register = '/register',
Maintenance = '/maintenance',
}

const routes: RouteRecordRaw[] = [
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -156,6 +162,10 @@ const routes: RouteRecordRaw[] = [
path: 'register',
component: RegisterDapp,
},
{
path: 'maintenance',
component: MaintenanceMode,
},
],
},

Expand Down
50 changes: 50 additions & 0 deletions src/staking-v3/components/MaintenanceMode.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<template>
<div class="wrapper--maintenance">
<div class="header--text">{{ $t('dappStaking.maintenance.switching') }}</div>
<div class="main--text">V3</div>
<div class="footer--text">{{ $t('dappStaking.maintenance.willBeBack') }}</div>
<div class="footer--text">{{ $t('dappStaking.maintenance.verySoon') }}</div>
</div>
</template>

<style lang="scss" scoped>
@import 'src/css/quasar.variables.scss';
.wrapper--maintenance {
margin-top: 32px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
font-size: 24px;
font-style: normal;
font-weight: 700;
line-height: normal;
background: url('/images/bk_maintenance.png') no-repeat center;
color: $container-bg-white;
}
.header--text {
font-size: 20px;
font-style: normal;
font-weight: 600;
line-height: 96.8%;
}
.main--text {
font-size: 48px;
font-style: normal;
font-weight: 900;
line-height: 96.8%;
margin: 16px 0;
}
.footer--text {
font-size: 14px;
font-style: normal;
font-weight: 600;
line-height: normal;
letter-spacing: 2.8px;
}
</style>
17 changes: 2 additions & 15 deletions src/v2/services/implementations/MetamaskWalletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -122,21 +123,7 @@ export class MetamaskWalletService extends WalletService implements IWalletServi
}: ParamSendEvmTransaction): Promise<string> {
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 })
Expand Down
44 changes: 18 additions & 26 deletions src/v2/services/implementations/XcmEvmService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 })
Expand Down

0 comments on commit e1cd87f

Please sign in to comment.