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

test: use wallet connect with thirdweb #1263

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/hooks/helper/wallet.ts
Expand Up @@ -11,15 +11,15 @@ import { supportEvmWalletObj, SupportWallet, supportWalletObj } from 'src/config
import { EVM, rpcUrls } from 'src/config/web3';
import { ETHEREUM_EXTENSION } from 'src/hooks';
import { EthereumProvider } from 'src/hooks/types/CustomSignature';
import { deepLink } from 'src/links';
import { deepLink, productionOrigin } from 'src/links';
import { addTxHistories } from 'src/modules/account';
import { HistoryTxType } from 'src/modules/account/index';
import { showError } from 'src/modules/extrinsic';
import { SubstrateAccount } from 'src/store/general/state';
import { container } from 'src/v2/common';
import { Symbols } from 'src/v2/symbols';
import { Dispatch } from 'vuex';
import { WalletConnectModal } from '@walletconnect/modal';
import { WalletConnectModal, WalletConnectModalConfig } from '@walletconnect/modal';

declare global {
interface Window {
Expand Down Expand Up @@ -292,14 +292,23 @@ const initWcProvider = async (): Promise<typeof WcEthereumProvider> => {

// Memo: this can be committed as it can be exposed on the browser anyway
const projectId = 'c236cca5c68248680dd7d0bf30fefbb5';
const isProductionPage = window.location.origin === productionOrigin;

// Ref: https://docs.walletconnect.com/advanced/walletconnectmodal/options#explorerrecommendedwalletids-optional
// Memo: disabled 'desktop wallet' section as it doesn't work for our zkEVM wallet. We might want to filter the wallet by ids in the future
new WalletConnectModal({
projectId,
explorerRecommendedWalletIds: 'NONE',
// explorerExcludedWalletIds: 'ALL',
});
// Memo: disabled 'desktop wallet' section for production page as it doesn't work for our zkEVM wallet. We might want to filter the wallet by ids in the future
const walletConnectParams = isProductionPage
? {
projectId,
explorerRecommendedWalletIds: 'NONE',
// explorerExcludedWalletIds: 'ALL',
}
: {
projectId,
explorerRecommendedWalletIds: 'ALL',
// explorerExcludedWalletIds: 'ALL',
};

new WalletConnectModal(walletConnectParams as WalletConnectModalConfig);

// Ref: https://docs.walletconnect.com/advanced/providers/ethereum
const provider = (await WcEthereumProvider.init({
Expand Down
16 changes: 11 additions & 5 deletions src/v2/services/implementations/AssetsService.ts
Expand Up @@ -38,11 +38,14 @@ export class AssetsService implements IAssetsService {
}

public async transferNativeAsset(param: ParamAssetTransfer): Promise<void> {
console.log('transferNativeAsset');
const useableBalance = await this.AssetsRepository.getNativeBalance(param.senderAddress);
const isBalanceEnough =
Number(ethers.utils.formatEther(useableBalance)) -
Number(ethers.utils.formatEther(param.amount)) >
REQUIRED_MINIMUM_BALANCE;
console.log('useableBalance', ethers.utils.formatEther(useableBalance));
// const isBalanceEnough =
// Number(ethers.utils.formatEther(useableBalance)) -
// Number(ethers.utils.formatEther(param.amount)) >
// REQUIRED_MINIMUM_BALANCE;
const isBalanceEnough = true;

if (isBalanceEnough) {
const transaction = await this.AssetsRepository.getNativeTransferCall(param);
Expand All @@ -58,6 +61,7 @@ export class AssetsService implements IAssetsService {
}

public async transferEvmAsset(param: ParamEvmTransfer): Promise<void> {
console.log('transferEvmAsset');
const provider = getEvmProvider(this.currentWallet as any);
const web3 = new Web3(provider as any);
const t = container.get<ComposerTranslation>(Symbols.I18Translation);
Expand All @@ -69,6 +73,7 @@ export class AssetsService implements IAssetsService {

const balWei = await web3.eth.getBalance(param.senderAddress);
const useableBalance = Number(ethers.utils.formatEther(balWei));
console.log('useableBalance', useableBalance);
const amount = param.contractAddress === astarNativeTokenErcAddr ? Number(param.amount) : 0;
const networkIdxStore = String(localStorage.getItem(LOCAL_STORAGE.NETWORK_IDX));

Expand All @@ -77,7 +82,8 @@ export class AssetsService implements IAssetsService {
? REQUIRED_MINIMUM_BALANCE_ETH
: REQUIRED_MINIMUM_BALANCE;

const isBalanceEnough = useableBalance - amount > minBal;
// const isBalanceEnough = useableBalance - amount > minBal;
const isBalanceEnough = true;
if (isBalanceEnough) {
const rawTx = await this.AssetsRepository.getEvmTransferData({
param,
Expand Down