Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for provider not set or invalid error #970

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/assets/transfer/LocalTransfer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
</div>
</div>

<div class="separator" />
<div v-if="isEnableSpeedConfiguration" class="separator" />

<speed-configuration
v-if="isEnableSpeedConfiguration"
Expand Down
1 change: 1 addition & 0 deletions src/config/web3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export {
getTokenExplorer,
fetchErc20TokenInfo,
getTokenDetails,
checkIsSetGasByWallet,
} from 'src/config/web3/utils';

export { contractInstance, Staking } from 'src/config/web3/contracts';
Expand Down
9 changes: 9 additions & 0 deletions src/config/web3/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,12 @@ export const fetchErc20TokenInfo = async ({
return null;
}
};

export const checkIsSetGasByWallet = (chainId: EVM): boolean => {
switch (chainId) {
case EVM.SHIBUYA_TESTNET:
return true;
default:
return false;
}
};
4 changes: 2 additions & 2 deletions src/hooks/transfer/useTokenTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ export function useTokenTransfer(selectedToken: Ref<Asset>) {
if (isLoading.value) return;
const transferAmtRef = Number(transferAmt.value);
try {
if (transferAmtRef > fromAddressBalance.value) {
if (transferAmtRef && transferAmtRef > fromAddressBalance.value) {
errMsg.value = t('warning.insufficientBalance', {
token: selectedToken.value.metadata.symbol,
});
} else if (toAddress.value && !isValidDestAddress.value) {
errMsg.value = 'warning.inputtedInvalidDestAddress';
} else if (!transferableBalance.value && !isH160.value) {
} else if (transferAmtRef && !transferableBalance.value && !isH160.value) {
errMsg.value = t('warning.insufficientBalance', {
token: nativeTokenSymbol.value,
});
Expand Down
13 changes: 11 additions & 2 deletions src/hooks/useGasPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const useGasPrice = (isFetch = false) => {
const network = computed<string>(() => {
return isMainnet ? currentNetworkName.value.toLowerCase() : 'shibuya';
});
const isH160 = computed<boolean>(() => store.getters['general/isH160Formatted']);
const isShibuyaEvm = computed<boolean>(() => isH160.value && network.value === 'shibuya');

const setSelectedGas = (speed: Speed): void => {
selectedGas.value = {
Expand Down Expand Up @@ -86,14 +88,21 @@ export const useGasPrice = (isFetch = false) => {
return (
currentWallet !== SupportWallet.TalismanEvm &&
currentWallet !== SupportWallet.SubWalletEvm &&
currentWallet !== SupportWallet.OneKeyEvm
currentWallet !== SupportWallet.OneKeyEvm &&
!isShibuyaEvm.value
);
});

watch(
[network, $web3],
async () => {
if (isFetch && network.value && !gas.value && $web3.value) {
if (
isFetch &&
network.value &&
!gas.value &&
$web3.value &&
isEnableSpeedConfiguration.value
) {
// console.info('gas price', network.value, gas.value);
await dispatchGasPrice(network.value);
}
Expand Down
4 changes: 4 additions & 0 deletions src/v2/app.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export function setCurrentWallet(
currentWallet: string,
isLockdrop: boolean
): void {
if (!currentWallet) {
return;
}

currentWalletType = isEthWallet ? WalletType.Metamask : WalletType.Polkadot;
currentWalletName = currentWallet;
isLockdropAccount = isLockdrop;
Expand Down
10 changes: 1 addition & 9 deletions src/v2/repositories/implementations/AssetsRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IAssetsRepository } from './../IAssetsRepository';
import { BN } from '@polkadot/util';
import { TransactionConfig } from 'web3-eth';
import Web3 from 'web3';
import { buildEvmAddress, getEvmGas } from '@astar-network/astar-sdk-core';
import { buildEvmAddress } from '@astar-network/astar-sdk-core';
import { AbiItem } from 'web3-utils';
import ERC20_ABI from 'src/config/abi/ERC20.json';
import { IGasPriceProvider } from 'src/v2/services';
Expand Down Expand Up @@ -44,14 +44,8 @@ export class AssetsRepository implements IAssetsRepository {
web3: Web3;
}): Promise<TransactionConfig> {
const { contractAddress, senderAddress, toAddress, amount, decimals } = param;
const [nonce, gasPrice] = await Promise.all([
web3.eth.getTransactionCount(senderAddress),
getEvmGas(web3, this.gasPriceProvider.getGas().price),
]);
if (contractAddress === astarNativeTokenErcAddr) {
return {
nonce,
gasPrice: web3.utils.toHex(gasPrice),
from: senderAddress,
to: toAddress,
value: web3.utils.toWei(String(amount), 'ether'),
Expand All @@ -60,8 +54,6 @@ export class AssetsRepository implements IAssetsRepository {
const contract = new web3.eth.Contract(ERC20_ABI as AbiItem[], contractAddress);
const amt = ethers.utils.parseUnits(String(amount), decimals).toString();
return {
nonce,
gasPrice: web3.utils.toHex(gasPrice),
from: senderAddress,
to: contractAddress,
value: '0x0',
Expand Down
11 changes: 8 additions & 3 deletions src/v2/services/implementations/MetamaskWalletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { WalletService } from 'src/v2/services/implementations';
import { Symbols } from 'src/v2/symbols';
import Web3 from 'web3';
import { checkIsSetGasByWallet } from 'src/config/web3';

@injectable()
export class MetamaskWalletService extends WalletService implements IWalletService {
Expand Down Expand Up @@ -127,17 +128,21 @@ export class MetamaskWalletService extends WalletService implements IWalletServi
web3.eth.getTransactionCount(from),
getEvmGas(web3, this.gasPriceProvider.getGas().price),
]);

const rawTx = {
nonce,
gasPrice: web3.utils.toHex(gasPrice),
from,
to,
value: value ? value : '0x0',
data,
};
const estimatedGas = await web3.eth.estimateGas(rawTx);

const connectedChainId = await web3.eth.net.getId();
const isSetGasByWallet = checkIsSetGasByWallet(connectedChainId);
const txParam = isSetGasByWallet ? rawTx : { ...rawTx, gasPrice: web3.utils.toHex(gasPrice) };
const estimatedGas = await web3.eth.estimateGas(txParam);
const transactionHash = await web3.eth
.sendTransaction({ ...rawTx, gas: estimatedGas })
.sendTransaction({ ...txParam, gas: estimatedGas })
.once('transactionHash', (transactionHash) => {
this.eventAggregator.publish(new BusyMessage(true));
})
Expand Down
Loading