update: don't delete accounts without password if settings encryption is enabled

This commit is contained in:
Andrei O 2022-10-17 02:21:07 +03:00
parent ee187db4f5
commit eedacacf89
No known key found for this signature in database
GPG Key ID: B961E5B68389457E
7 changed files with 114 additions and 18 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "clear-wallet", "name": "clear-wallet",
"version": "1.0.7", "version": "1.0.8",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
@ -27,6 +27,7 @@
"devDependencies": { "devDependencies": {
"@capacitor/cli": "^4.3.0", "@capacitor/cli": "^4.3.0",
"@crxjs/vite-plugin": "^1.0.14", "@crxjs/vite-plugin": "^1.0.14",
"@types/archiver": "^5.3.1",
"@types/jest": "^29.0.3", "@types/jest": "^29.0.3",
"@types/node": "^18.7.19", "@types/node": "^18.7.19",
"@typescript-eslint/eslint-plugin": "^5.38.0", "@typescript-eslint/eslint-plugin": "^5.38.0",

View File

@ -1,10 +1,16 @@
import archiver from 'archiver'; const pFs = import('fs')
import fs from 'fs'; const pCps = import ('child_process')
import { spawn } from 'child_process';
async function ghRelease(changes: string[]) {
const fs = (await pFs).default
if (!fs.existsSync('releases')){
fs.mkdirSync('releases');
}
async function ghRelease(changes) {
const pkg = JSON.parse(fs.readFileSync('package.json').toString()); const pkg = JSON.parse(fs.readFileSync('package.json').toString());
const archiver = (await import('archiver')).default
const archive = archiver('zip', { zlib: { level: 9 } }); const archive = archiver('zip', { zlib: { level: 9 } });
const dirPipes = ['dist']; const dirPipes = ['dist'];
@ -20,7 +26,7 @@ async function ghRelease(changes) {
filePipes.forEach((file) => { filePipes.forEach((file) => {
arch = arch.file(file, { name: file }); arch = arch.file(file, { name: file });
}); });
arch.on('error', (err) => reject(err)).pipe(outputZip); arch.on('error', (err: unknown) => reject(err)).pipe(outputZip);
outputZip.on('close', () => resolve(true)); outputZip.on('close', () => resolve(true));
arch.finalize(); arch.finalize();
@ -31,14 +37,14 @@ async function ghRelease(changes) {
fs.writeFileSync( fs.writeFileSync(
changeLogPath, changeLogPath,
`# ${pkg.version} \n `# ${pkg.version} \n
${changes.reduce((acc, change) => { ${changes.reduce((acc: string, change: string) => {
return acc + `- ${change}\n`; return acc + `- ${change}\n`;
}, '')}`, }, '')}`,
); );
const cps = (await pCps)
console.log( console.log(
await new Promise((resolve) => { await new Promise((resolve) => {
const p = spawn('gh', ['release', 'create', `v${pkg.version}`, `./${outputPath}`, '-F', `./${changeLogPath}`], { const p = cps.spawn('gh', ['release', 'create', `v${pkg.version}`, `./${outputPath}`, '-F', `./${changeLogPath}`], {
shell: true, shell: true,
}); });
// const p = spawn('pwd'); // const p = spawn('pwd');

View File

@ -3,8 +3,8 @@
"name": "__MSG_appName__", "name": "__MSG_appName__",
"description": "__MSG_appDesc__", "description": "__MSG_appDesc__",
"default_locale": "en", "default_locale": "en",
"version": "1.0.5", "version": "1.0.8",
"version_name": "1.0.5", "version_name": "1.0.8",
"icons": { "icons": {
"16": "assets/extension-icon/wallet_16.png", "16": "assets/extension-icon/wallet_16.png",
"32": "assets/extension-icon/wallet_32.png", "32": "assets/extension-icon/wallet_32.png",

View File

@ -96,6 +96,7 @@ chrome.runtime.onMessage.addListener((message: RequestArguments, sender, sendRes
break break
} }
case 'eth_getBlockByNumber': { case 'eth_getBlockByNumber': {
try {
const params = message?.params?.[0] as any const params = message?.params?.[0] as any
const block = await getBlockByNumber(params) as any const block = await getBlockByNumber(params) as any
block.gasLimit = block.gasLimit.toHexString() block.gasLimit = block.gasLimit.toHexString()
@ -103,29 +104,77 @@ chrome.runtime.onMessage.addListener((message: RequestArguments, sender, sendRes
block.baseFeePerGas = block.baseFeePerGas.toHexString() block.baseFeePerGas = block.baseFeePerGas.toHexString()
block._difficulty = block._difficulty.toHexString() block._difficulty = block._difficulty.toHexString()
sendResponse(block) sendResponse(block)
} catch {
sendResponse({
error: true,
code: rpcError.USER_REJECTED,
message: 'No network or user selected'
})
}
break; break;
} }
case 'eth_getTransactionByHash': { case 'eth_getTransactionByHash': {
try {
sendResponse(await getTxByHash(message?.params?.[0] as string)) sendResponse(await getTxByHash(message?.params?.[0] as string))
} catch {
sendResponse({
error: true,
code: rpcError.USER_REJECTED,
message: 'No network or user selected'
})
}
break break
} }
case 'eth_getTransactionReceipt':{ case 'eth_getTransactionReceipt':{
try {
sendResponse(await getTxReceipt(message?.params?.[0] as string)) sendResponse(await getTxReceipt(message?.params?.[0] as string))
} catch {
sendResponse({
error: true,
code: rpcError.USER_REJECTED,
message: 'No network or user selected'
})
}
break break
} }
case 'eth_gasPrice': { case 'eth_gasPrice': {
try {
sendResponse((await getGasPrice()).toHexString()) sendResponse((await getGasPrice()).toHexString())
} catch {
sendResponse({
error: true,
code: rpcError.USER_REJECTED,
message: 'No network or user selected'
})
}
break; break;
} }
case 'eth_getBalance': { case 'eth_getBalance': {
try {
sendResponse(await getBalance()) sendResponse(await getBalance())
} catch {
sendResponse({
error: true,
code: rpcError.USER_REJECTED,
message: 'No network or user selected'
})
}
break break
} }
case 'eth_blockNumber': { case 'eth_blockNumber': {
try {
sendResponse(await getBlockNumber()) sendResponse(await getBlockNumber())
} catch {
sendResponse({
error: true,
code: rpcError.USER_REJECTED,
message: 'No network or user selected'
})
}
break break
} }
case 'eth_estimateGas': { case 'eth_estimateGas': {
try {
const params = message?.params?.[0] as any const params = message?.params?.[0] as any
if(!params) { if(!params) {
sendResponse({ sendResponse({
@ -141,7 +190,14 @@ chrome.runtime.onMessage.addListener((message: RequestArguments, sender, sendRes
data: params?.data ?? '', data: params?.data ?? '',
value: params?.value ?? '0x0' value: params?.value ?? '0x0'
})) }))
break } catch {
sendResponse({
error: true,
code: rpcError.USER_REJECTED,
message: 'No network or user selected'
})
}
break
} }
case 'eth_requestAccounts': case 'eth_requestAccounts':
case 'eth_accounts': { case 'eth_accounts': {

View File

@ -69,7 +69,7 @@
<script lang="ts"> <script lang="ts">
import { defineComponent, ref, Ref } from "vue"; import { defineComponent, ref, Ref } from "vue";
import { getAccounts, copyAddress, replaceAccounts, getSettings, clearPk } from "@/utils/platform" import { getAccounts, copyAddress, replaceAccounts, getSettings, clearPk, getSelectedAccount, saveSelectedAccount } from "@/utils/platform"
import { import {
IonContent, IonContent,
IonHeader, IonHeader,
@ -136,11 +136,23 @@ export default defineComponent({
const deleteAccount = async (address: string) => { const deleteAccount = async (address: string) => {
loading.value = true loading.value = true
if(settings.value.enableStorageEnctyption) {
const modalR = await openModal('delAcc')
if(!modalR){
return
}
}
const findIndex = accounts.value.findIndex(a => a.address === address) const findIndex = accounts.value.findIndex(a => a.address === address)
const selectedAccount = await getSelectedAccount()
const pArr: Array<Promise<void>> = []
if (findIndex !== -1) { if (findIndex !== -1) {
accounts.value.splice(findIndex, 1) accounts.value.splice(findIndex, 1)
pArr.push(replaceAccounts([...accounts.value]))
} }
await replaceAccounts([...accounts.value]) if(selectedAccount.address === address) {
pArr.push(saveSelectedAccount({ name: '', pk: '', encPk: '', address: ''}))
}
await Promise.all(pArr)
loading.value = false loading.value = false
} }
@ -156,11 +168,11 @@ export default defineComponent({
loadData() loadData()
}) })
const openModal = async () => { const openModal = async (type: string) => {
const modal = await modalController.create({ const modal = await modalController.create({
component: UnlockModal, component: UnlockModal,
componentProps: { componentProps: {
unlockType: 'viewPk' unlockType: type
} }
}); });
@ -175,7 +187,7 @@ export default defineComponent({
const account = accounts.value.find(a => a.address === addr) const account = accounts.value.find(a => a.address === addr)
if(settings.value.enableStorageEnctyption) { if(settings.value.enableStorageEnctyption) {
if(account?.encPk) { if(account?.encPk) {
const modalR = await openModal() const modalR = await openModal('viewPk')
if(modalR){ if(modalR){
const account = (await getAccounts()).find(a => a.address === addr) const account = (await getAccounts()).find(a => a.address === addr)
pk = account?.pk ?? '' pk = account?.pk ?? ''

View File

@ -13,7 +13,8 @@
"baseUrl": ".", "baseUrl": ".",
"types": [ "types": [
"chrome", "chrome",
"jest" "jest",
"node"
], ],
"paths": { "paths": {
"@/*": [ "@/*": [

View File

@ -1396,6 +1396,13 @@
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.3.tgz#472eaab5f15c1ffdd7f8628bd4c4f753995ec79e" resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.3.tgz#472eaab5f15c1ffdd7f8628bd4c4f753995ec79e"
integrity sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ== integrity sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==
"@types/archiver@^5.3.1":
version "5.3.1"
resolved "https://registry.yarnpkg.com/@types/archiver/-/archiver-5.3.1.tgz#02991e940a03dd1a32678fead4b4ca03d0e387ca"
integrity sha512-wKYZaSXaDvTZuInAWjCeGG7BEAgTWG2zZW0/f7IYFcoHB2X2d9lkVFnrOlXl3W6NrvO6Ml3FLLu8Uksyymcpnw==
dependencies:
"@types/glob" "*"
"@types/babel__core@^7.1.14": "@types/babel__core@^7.1.14":
version "7.1.19" version "7.1.19"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.19.tgz#7b497495b7d1b4812bdb9d02804d0576f43ee460" resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.19.tgz#7b497495b7d1b4812bdb9d02804d0576f43ee460"
@ -1461,6 +1468,14 @@
dependencies: dependencies:
"@types/node" "*" "@types/node" "*"
"@types/glob@*":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-8.0.0.tgz#321607e9cbaec54f687a0792b2d1d370739455d2"
integrity sha512-l6NQsDDyQUVeoTynNpC9uRvCUint/gSUXQA2euwmTuWGvPY5LSDUu6tkCtJB2SvGQlJQzLaKqcGZP4//7EDveA==
dependencies:
"@types/minimatch" "*"
"@types/node" "*"
"@types/graceful-fs@^4.1.3": "@types/graceful-fs@^4.1.3":
version "4.1.5" version "4.1.5"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15" resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15"
@ -1505,6 +1520,11 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.11.tgz#d421b6c527a3037f7c84433fd2c4229e016863d3"
integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ== integrity sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==
"@types/minimatch@*":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca"
integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==
"@types/node@*": "@types/node@*":
version "18.7.13" version "18.7.13"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.7.13.tgz#23e6c5168333480d454243378b69e861ab5c011a" resolved "https://registry.yarnpkg.com/@types/node/-/node-18.7.13.tgz#23e6c5168333480d454243378b69e861ab5c011a"