diff --git a/package.json b/package.json index 1797ffe..2c03b86 100644 --- a/package.json +++ b/package.json @@ -14,44 +14,44 @@ "pub": "yarn build && yarn release && ts-node ./release-scripts/create-release.ts" }, "dependencies": { - "@capacitor/app": "^4.1.1", - "@capacitor/core": "^4.7.1", - "@capacitor/haptics": "^4.1.0", - "@capacitor/keyboard": "^4.1.1", - "@capacitor/status-bar": "^4.1.1", - "@ionic/vue": "^7.0.0", - "@ionic/vue-router": "^7.0.0", - "@types/chrome": "^0.0.227", - "core-js": "^3.29.1", - "ethers": "^5.7.2", - "vue": "^3.2.47", - "vue-router": "^4.1.6" + "@capacitor/app": "^5.0.6", + "@capacitor/core": "^5.2.3", + "@capacitor/haptics": "^5.0.6", + "@capacitor/keyboard": "^5.0.6", + "@capacitor/status-bar": "^5.0.6", + "@ionic/vue": "^7.2.3", + "@ionic/vue-router": "^7.2.3", + "@types/chrome": "^0.0.243", + "core-js": "^3.32.0", + "ethers": "^6.7.0", + "vue": "^3.3.4", + "vue-router": "^4.2.4" }, "devDependencies": { - "@capacitor/cli": "^4.7.1", + "@capacitor/cli": "^5.2.3", "@crxjs/vite-plugin": "^1.0.14", "@types/archiver": "^5.3.2", - "@types/jest": "^29.5.0", - "@types/node": "^18.15.11", - "@typescript-eslint/eslint-plugin": "^5.57.0", - "@typescript-eslint/parser": "^5.57.0", - "@vitejs/plugin-vue": "^4.1.0", - "@vue/eslint-config-typescript": "^11.0.2", + "@types/jest": "^29.5.3", + "@types/node": "^20.5.0", + "@typescript-eslint/eslint-plugin": "^6.3.0", + "@typescript-eslint/parser": "^6.3.0", + "@vitejs/plugin-vue": "^4.2.3", + "@vue/eslint-config-typescript": "^11.0.3", "archiver": "^5.3.1", - "eslint": "^8.37.0", - "eslint-plugin-vue": "^9.10.0", + "eslint": "^8.47.0", + "eslint-plugin-vue": "^9.17.0", "http-browserify": "^1.7.0", "https-browserify": "^1.0.0", - "jest": "^29.5.0", + "jest": "^29.6.2", "rollup-plugin-polyfill-node": "^0.12.0", - "sass": "^1.60.0", + "sass": "^1.65.1", "stream-browserify": "^3.0.0", - "ts-jest": "^29.0.5", + "ts-jest": "^29.1.1", "ts-node": "^10.9.1", - "typescript": "^5.0.2", + "typescript": "^5.1.6", "util": "^0.12.5", - "vite": "^4.2.1", - "vue-tsc": "^1.2.0", + "vite": "^4.4.9", + "vue-tsc": "^1.8.8", "yarn-upgrade-all": "^0.7.2" }, "description": "An Ionic project" diff --git a/src/extension/serviceWorker.ts b/src/extension/serviceWorker.ts index be5b9ff..379dc5e 100644 --- a/src/extension/serviceWorker.ts +++ b/src/extension/serviceWorker.ts @@ -154,7 +154,7 @@ const mainListner = (message: RequestArguments, sender:any, sendResponse: (a: an } case 'eth_gasPrice': { try { - sendResponse((await getGasPrice()).toHexString()) + sendResponse(strToHex(String(await getGasPrice() ?? 0))) } catch { sendResponse({ error: true, @@ -217,7 +217,7 @@ const mainListner = (message: RequestArguments, sender:any, sendResponse: (a: an data: params?.data ?? '', value: params?.value ?? '0x0' }) - const gasHex = gas?._hex ? gas?._hex : gas + const gasHex = strToHex(String(gas ?? 0)) sendResponse(gasHex) } catch(err) { if(String(err).includes('UNPREDICTABLE_GAS_LIMIT')) { @@ -327,7 +327,7 @@ const mainListner = (message: RequestArguments, sender:any, sendResponse: (a: an }) try { - const tx = await sendTransaction({...params, ...(rIdData?.[String(gWin?.id ?? 0)] ?? {}) }, pEstimateGas, pGasPrice) + const tx = await sendTransaction({...params, ...(rIdData?.[String(gWin?.id ?? 0)] ?? {}) }, pEstimateGas, pGasPrice ) sendResponse(tx.hash) const buttons = {} as any const network = await getSelectedNetwork() diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 4c503a6..884ceac 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -8,4 +8,4 @@ export const exportFile = (fileName: string, content: string, type = 'json') => document.body.appendChild(link) link.click() document.body.removeChild(link) - } \ No newline at end of file + } diff --git a/src/utils/platform.ts b/src/utils/platform.ts index 51c3a8c..5b2943f 100644 --- a/src/utils/platform.ts +++ b/src/utils/platform.ts @@ -176,7 +176,7 @@ export const hexTostr = (hexStr: string) => return hexStr } -export const strToHex = (str: string) => `0x${str.split('').map( s => s.charCodeAt(0).toString(16) ).join('')}` +export const strToHex = (str: string) => `0x${str.split('').map( s => s.charCodeAt(0).toString(16)).join('')}` export const numToHexStr = (num: number) => `0x${num.toString(16)}` diff --git a/src/utils/wallet.ts b/src/utils/wallet.ts index 464ba7b..c31b596 100644 --- a/src/utils/wallet.ts +++ b/src/utils/wallet.ts @@ -1,10 +1,12 @@ import { getSelectedAccount, getSelectedNetwork } from '@/utils/platform'; -import { BigNumber, ethers } from "ethers" +import { ethers } from "ethers" +import { strToHex } from '@/utils/platform'; + export const signMsg = async (msg: string) => { const account = await getSelectedAccount() const wallet = new ethers.Wallet(account.pk) - return await wallet.signMessage( msg.startsWith('0x') ? ethers.utils.arrayify(msg): msg) + return await wallet.signMessage( msg.startsWith('0x') ? ethers.getBytes(msg): msg) } export const signTypedData = async (msg: string) => { @@ -18,73 +20,77 @@ export const signTypedData = async (msg: string) => { } } } - return await wallet._signTypedData(parsedMsg.domain, parsedMsg.types, parsedMsg.message) + + return await wallet.signTypedData(parsedMsg.domain, parsedMsg.types, parsedMsg.message) } export const getBalance = async () =>{ const account = await getSelectedAccount() const network = await getSelectedNetwork() - const provider = new ethers.providers.JsonRpcProvider(network.rpc) + const provider = new ethers.JsonRpcProvider(network.rpc) return await provider.getBalance(account.address) } export const getGasPrice = async () => { const network = await getSelectedNetwork() - const provider = new ethers.providers.JsonRpcProvider(network.rpc) - return await provider.getGasPrice() + const provider = new ethers.JsonRpcProvider(network.rpc) + const feed = await provider.getFeeData() + const gasPrice = feed.gasPrice ?? feed.maxFeePerGas + return gasPrice } export const getBlockNumber = async () => { const network = await getSelectedNetwork() - const provider = new ethers.providers.JsonRpcProvider(network.rpc) + const provider = new ethers.JsonRpcProvider(network.rpc) return await provider.getBlockNumber() } export const getBlockByNumber = async (blockNum: number) => { const network = await getSelectedNetwork() - const provider = new ethers.providers.JsonRpcProvider(network.rpc) + const provider = new ethers.JsonRpcProvider(network.rpc) return await provider.getBlock(blockNum) } export const estimateGas = async ({to = '', from = '', data = '', value = '0x0' }: {to: string, from: string, data: string, value: string}) => { const network = await getSelectedNetwork() - const provider = new ethers.providers.JsonRpcProvider(network.rpc) + const provider = new ethers.JsonRpcProvider(network.rpc) return await provider.estimateGas({to, from, data, value}) } export const evmCall = async ({to = '', from = '', data = '', value = '0x0' }: {to: string, from: string, data: string, value: string}) => { const network = await getSelectedNetwork() - const provider = new ethers.providers.JsonRpcProvider(network.rpc) + const provider = new ethers.JsonRpcProvider(network.rpc) return await provider.call({to, from, data, value}) } export const getTxByHash = async (hash: string) => { const network = await getSelectedNetwork() - const provider = new ethers.providers.JsonRpcProvider(network.rpc) + const provider = new ethers.JsonRpcProvider(network.rpc) return await provider.getTransaction(hash) } export const getTxReceipt = async (hash: string) => { const network = await getSelectedNetwork() - const provider = new ethers.providers.JsonRpcProvider(network.rpc) + const provider = new ethers.JsonRpcProvider(network.rpc) return await provider.getTransactionReceipt(hash) } export const getCode = async (addr: string) => { const network = await getSelectedNetwork() - const provider = new ethers.providers.JsonRpcProvider(network.rpc) + const provider = new ethers.JsonRpcProvider(network.rpc) return await provider.getCode(addr) } -export const getFromMemonic = (memonic: string, index: number) => { +export const getFromMnemonic = (mnemonic: string, index: number) => { const path = `m/44'/60'/0'/0/${index}` - const wallet = ethers.Wallet.fromMnemonic(memonic, path) + const mnemonicInst = ethers.Mnemonic.fromPhrase(mnemonic) + const wallet = ethers.HDNodeWallet.fromMnemonic(mnemonicInst, path) return wallet.privateKey } export const getTxCount = async (addr: string, block: null | string = null) => { const network = await getSelectedNetwork() - const provider = new ethers.providers.JsonRpcProvider(network.rpc) + const provider = new ethers.JsonRpcProvider(network.rpc) if(block){ return await provider.getTransactionCount(addr, block) } else { @@ -94,10 +100,10 @@ export const getTxCount = async (addr: string, block: null | string = null) => { export const sendTransaction = async ({ data= '', gas='0x0', to='', from='', value='0x0', gasPrice='0x0'}: {to: string, from: string, data: string, value: string, gas: string, gasPrice: string}, -gasEstimate: Promise | null = null, pGasPrice : Promise | null) => { +gasEstimate: Promise | null = null, pGasPrice : Promise | null) => { const account = await getSelectedAccount() const network = await getSelectedNetwork() - const wallet = new ethers.Wallet(account.pk, new ethers.providers.JsonRpcProvider(network.rpc)) + const wallet = new ethers.Wallet(account.pk, new ethers.JsonRpcProvider(network.rpc)) if(gas === '0x0') { if(!gasEstimate){ throw new Error('No gas estimate available') @@ -110,9 +116,16 @@ gasEstimate: Promise | null = null, pGasPrice : Promise | if(!pGasPrice){ throw new Error('No gas estimate available') }else { - gasPrice = (await pGasPrice).toString() + gasPrice = (await pGasPrice ?? 0).toString() } } + + console.log('gasPrice', gasPrice) + console.log('gas', gas) + + if(gas === '0x0' || gasPrice === '0x0' || 1 === 1) { + throw new Error('No gas estimate available') + } return await wallet.sendTransaction({to, from, data, value, gasLimit: gas, gasPrice}) } @@ -120,5 +133,5 @@ export const formatBalance = (balance: string) => { Intl.NumberFormat('en-US', { notation: 'compact', maximumFractionDigits: 6 - }).format(Number(ethers.utils.parseEther(balance))) + }).format(Number(ethers.parseEther(balance))) } diff --git a/src/views/AccountsTab.vue b/src/views/AccountsTab.vue index a5c3d8b..4b7ac67 100644 --- a/src/views/AccountsTab.vue +++ b/src/views/AccountsTab.vue @@ -4,72 +4,75 @@ - - - - - + + + + + Accounts - + No EVM accounts found Add Account - - - + + + {{ account.name }} - - - -

{{ account.address }}

+
+
+ +

{{ account.address }}

+
- View Pk - Delete - Edit Name + View Pk + Delete + Edit Name -
+ - - - - - - Close - - View PK - - - - - - PK - - - + + + + + Close + + View PK + + + + + + PK + + + - -
diff --git a/src/views/AddAccount.vue b/src/views/AddAccount.vue index af37610..cf5cbaa 100644 --- a/src/views/AddAccount.vue +++ b/src/views/AddAccount.vue @@ -10,7 +10,7 @@ Name - + Get Random Name @@ -24,7 +24,7 @@ button /> PK - +