From e48657732c98e012e37141ef563f20047b8995ad Mon Sep 17 00:00:00 2001 From: Tomek Marciniak Date: Fri, 7 Jun 2024 08:41:57 +0200 Subject: [PATCH] fix(wallet): remove unnecessary permissions --- apps/extension/manifest.config.ts | 9 +-------- .../features/src/web-connector/routes/web-connector.tsx | 6 ++++-- .../chain-history/chain-history-provider.ts | 6 +----- .../block-listener/BlockListenerProvider.ts | 8 +------- .../mina-node/block-listener/BlockListenerProvider.ts | 8 +------- packages/providers/src/open-mina/start-node.ts | 1 - .../src/optimism/chain-history/chain-history-provider.ts | 6 +----- .../zeko-scan/chain-history/chain-history-provider.ts | 7 +------ packages/vault/src/vault/utils/switch-network.ts | 3 --- packages/vault/src/vault/utils/sync-wallet.ts | 2 -- packages/web-provider/src/mina-network/mina-provider.ts | 1 - packages/web-provider/src/vault-service/vault-service.ts | 4 +--- 12 files changed, 11 insertions(+), 50 deletions(-) diff --git a/apps/extension/manifest.config.ts b/apps/extension/manifest.config.ts index fc7c3ff7..e12816c9 100644 --- a/apps/extension/manifest.config.ts +++ b/apps/extension/manifest.config.ts @@ -25,14 +25,7 @@ export default defineManifest((env) => ({ version: `${major}.${minor}.${patch}.${label}`, version_name: version, action: { default_popup: "index.html" }, - permissions: [ - "storage", - "notifications", - "activeTab", - "offscreen", - "tabs", - "background", - ], + permissions: ["storage", "activeTab", "tabs", "background"], background: { service_worker: "src/background/index.ts", type: "module", diff --git a/packages/features/src/web-connector/routes/web-connector.tsx b/packages/features/src/web-connector/routes/web-connector.tsx index 6a4f6f60..2670bef4 100644 --- a/packages/features/src/web-connector/routes/web-connector.tsx +++ b/packages/features/src/web-connector/routes/web-connector.tsx @@ -42,8 +42,10 @@ export const WebConnectorRoute = () => { }) window.close() } - const parsedPayload = JSON.parse(payload) as Record - const yamlPayload = yaml.stringify(parsedPayload.data) ?? "" + const parsedPayload = payload + ? (JSON.parse(payload) as Record) + : {} + const yamlPayload = yaml.stringify(parsedPayload?.data) ?? "" const userFriendlyPayload = DOMPurify.sanitize(highlight(yamlPayload)) if (!rawWindowId) return null if (!inputType) return null diff --git a/packages/providers/src/blockberry-provider/chain-history/chain-history-provider.ts b/packages/providers/src/blockberry-provider/chain-history/chain-history-provider.ts index 8638da44..9675d356 100644 --- a/packages/providers/src/blockberry-provider/chain-history/chain-history-provider.ts +++ b/packages/providers/src/blockberry-provider/chain-history/chain-history-provider.ts @@ -2,7 +2,6 @@ import type { Mina } from "@palladxyz/mina-core" import type { ChainHistoryProvider, TransactionsByAddressesArgs, - TransactionsByHashesArgs, Tx, } from "@palladxyz/pallad-core" @@ -43,10 +42,7 @@ export const createChainHistoryProvider = ( return convertToTransactionBody(data.data) } // TODO: remove txByHashes method - const transactionsByHashes = async ( - args: TransactionsByHashesArgs, - ): Promise => { - console.log("args", args) + const transactionsByHashes = async (): Promise => { /*const promises = args.ids.map(id => { const endpoint = `${url}/api/core/transactions/${id}`; return fetch(endpoint).then(response => response.json()); diff --git a/packages/providers/src/mina-explorer/block-listener/BlockListenerProvider.ts b/packages/providers/src/mina-explorer/block-listener/BlockListenerProvider.ts index d501ca7b..21409358 100644 --- a/packages/providers/src/mina-explorer/block-listener/BlockListenerProvider.ts +++ b/packages/providers/src/mina-explorer/block-listener/BlockListenerProvider.ts @@ -61,9 +61,7 @@ export class BlockListenerProvider { if ("data" in result && "newBlock" in result.data) { const data: BlockData = result.data if (data.newBlock) { - console.log("Received block data:", data) - const accountInfo = await this.getAccountInfo({ publicKey }) - console.log("Received updated account info:", accountInfo) + await this.getAccountInfo({ publicKey }) } else { console.error("No new block data in result:", result) } @@ -75,16 +73,13 @@ export class BlockListenerProvider { } private async getAccountInfo(args: AccountInfoArgs): Promise { - console.log("Initiating getAccountInfo with args:", args) const query = gql` ${getAccountBalance} ` try { - console.log("Sending request for account info...") const data = (await this.gqlClient.request(query, { publicKey: args.publicKey, })) as AccountData - console.log("Received response for account info:", data) if (!data || !data.account) { throw new Error("Invalid account data response") @@ -100,7 +95,6 @@ export class BlockListenerProvider { } // if the node is available, then the account doesn't exist yet // return an empty account - console.log("Error in getAccountInfo, account does not exist yet!") return { balance: { total: 0 }, nonce: 0, diff --git a/packages/providers/src/mina-node/block-listener/BlockListenerProvider.ts b/packages/providers/src/mina-node/block-listener/BlockListenerProvider.ts index d501ca7b..21409358 100644 --- a/packages/providers/src/mina-node/block-listener/BlockListenerProvider.ts +++ b/packages/providers/src/mina-node/block-listener/BlockListenerProvider.ts @@ -61,9 +61,7 @@ export class BlockListenerProvider { if ("data" in result && "newBlock" in result.data) { const data: BlockData = result.data if (data.newBlock) { - console.log("Received block data:", data) - const accountInfo = await this.getAccountInfo({ publicKey }) - console.log("Received updated account info:", accountInfo) + await this.getAccountInfo({ publicKey }) } else { console.error("No new block data in result:", result) } @@ -75,16 +73,13 @@ export class BlockListenerProvider { } private async getAccountInfo(args: AccountInfoArgs): Promise { - console.log("Initiating getAccountInfo with args:", args) const query = gql` ${getAccountBalance} ` try { - console.log("Sending request for account info...") const data = (await this.gqlClient.request(query, { publicKey: args.publicKey, })) as AccountData - console.log("Received response for account info:", data) if (!data || !data.account) { throw new Error("Invalid account data response") @@ -100,7 +95,6 @@ export class BlockListenerProvider { } // if the node is available, then the account doesn't exist yet // return an empty account - console.log("Error in getAccountInfo, account does not exist yet!") return { balance: { total: 0 }, nonce: 0, diff --git a/packages/providers/src/open-mina/start-node.ts b/packages/providers/src/open-mina/start-node.ts index de0579fb..171192e3 100644 --- a/packages/providers/src/open-mina/start-node.ts +++ b/packages/providers/src/open-mina/start-node.ts @@ -11,7 +11,6 @@ function runCommand(command: string): Promise { console.error(`Stderr: ${stderr}`) return reject(new Error(stderr)) } - console.log(`Stdout: ${stdout}`) resolve() }) }) diff --git a/packages/providers/src/optimism/chain-history/chain-history-provider.ts b/packages/providers/src/optimism/chain-history/chain-history-provider.ts index b11f24bd..d7249c91 100644 --- a/packages/providers/src/optimism/chain-history/chain-history-provider.ts +++ b/packages/providers/src/optimism/chain-history/chain-history-provider.ts @@ -1,7 +1,6 @@ import type { ChainHistoryProvider, TransactionsByAddressesArgs, - TransactionsByHashesArgs, Tx, } from "@palladxyz/pallad-core" @@ -44,9 +43,7 @@ export const createChainHistoryProvider = ( return data.result } - const transactionsByHashes = async ( - args: TransactionsByHashesArgs, - ): Promise => { + const transactionsByHashes = async (): Promise => { // TODO: make dependency on etherscan /*const client = createPublicClient({ chain: args.chainInfo, @@ -59,7 +56,6 @@ export const createChainHistoryProvider = ( return transactions as any*/ await new Promise((resolve) => setTimeout(resolve, 500)) - console.log("args", args) return [] as Tx[] } diff --git a/packages/providers/src/zeko-scan/chain-history/chain-history-provider.ts b/packages/providers/src/zeko-scan/chain-history/chain-history-provider.ts index 427f636d..514ddd9a 100644 --- a/packages/providers/src/zeko-scan/chain-history/chain-history-provider.ts +++ b/packages/providers/src/zeko-scan/chain-history/chain-history-provider.ts @@ -2,7 +2,6 @@ import type { Mina } from "@palladxyz/mina-core" import type { ChainHistoryProvider, TransactionsByAddressesArgs, - TransactionsByHashesArgs, Tx, } from "@palladxyz/pallad-core" @@ -38,7 +37,6 @@ export const createChainHistoryProvider = ( // https://zekoscan.io/devnet/api/transactions/B62qq7ecvBQZQK68dwstL27888NEKZJwNXNFjTyu3xpQcfX5UBivCU6?page=0&limit=50&sortBy=height&orderBy=DESC&size=50&pk=B62qq7ecvBQZQK68dwstL27888NEKZJwNXNFjTyu3xpQcfX5UBivCU6&direction=all // https://zekoscan.io/devnet/api/transactions/B62qjsV6WQwTeEWrNrRRBP6VaaLvQhwWTnFi4WP4LQjGvpfZEumXzxb/page=0&limit=20&sortBy=height&orderBy=DESC&size=20&pk=B62qjsV6WQwTeEWrNrRRBP6VaaLvQhwWTnFi4WP4LQjGvpfZEumXzxb&direction=all const endpoint = `${url}/api/transactions/${args.addresses[0]}?page=0&limit=${limit}&sortBy=height&orderBy=DESC&size=${limit}&pk=${args.addresses[0]}&direction=all` - console.log("endpoint:", endpoint) const response = await fetch(endpoint) if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`) @@ -47,10 +45,7 @@ export const createChainHistoryProvider = ( return convertToTransactionBody(data.data, args.addresses[0] as string) } // TODO: remove txByHashes method - const transactionsByHashes = async ( - args: TransactionsByHashesArgs, - ): Promise => { - console.log("args", args) + const transactionsByHashes = async (): Promise => { /*const promises = args.ids.map(id => { const endpoint = `${url}/api/core/transactions/${id}`; return fetch(endpoint).then(response => response.json()); diff --git a/packages/vault/src/vault/utils/switch-network.ts b/packages/vault/src/vault/utils/switch-network.ts index e1a0cc58..0da64202 100644 --- a/packages/vault/src/vault/utils/switch-network.ts +++ b/packages/vault/src/vault/utils/switch-network.ts @@ -11,9 +11,7 @@ export async function switchNetworkHelper(get: any, networkName: string) { const currentWallet = getCurrentWallet() if (!currentWallet) throw new Error("Current wallet is null, empty or undefined") - console.log("current wallet in switchNetwork", currentWallet) const publicKey = await getCurrentWallet()?.credential?.credential?.address // todo: DRY this up - console.log("public key in switchNetwork", publicKey) if (!publicKey) throw new AddressError( "Wallet address is undefined in switchNetwork method", @@ -21,7 +19,6 @@ export async function switchNetworkHelper(get: any, networkName: string) { ensureAccount(networkName, publicKey) await setCurrentNetworkName(networkName) - console.log("networkName name in switch network", networkName) await _syncWallet(networkName) } diff --git a/packages/vault/src/vault/utils/sync-wallet.ts b/packages/vault/src/vault/utils/sync-wallet.ts index 6f80f432..7504b485 100644 --- a/packages/vault/src/vault/utils/sync-wallet.ts +++ b/packages/vault/src/vault/utils/sync-wallet.ts @@ -17,7 +17,6 @@ export async function syncWalletnHelper( } = get() // when the wallet bricks this public key is undefined. const currentwallet = getCurrentWallet() - console.log("currentWallet in syncWallet", currentwallet) const publicKey = currentwallet?.credential?.credential?.address // todo: DRY this up if (!publicKey) throw new AddressError("Wallet address is undefined in _syncWallet method") @@ -41,7 +40,6 @@ export async function syncWalletnHelper( } const response = await provider.getNodeStatus() - console.log("node response for chain info in syncWallet", response) if (!response.daemonStatus.chainId) { throw new Error( `Could not get chainId for ${syncProviderConfig} in updateChainId`, diff --git a/packages/web-provider/src/mina-network/mina-provider.ts b/packages/web-provider/src/mina-network/mina-provider.ts index aa66a25b..6a0580bd 100644 --- a/packages/web-provider/src/mina-network/mina-provider.ts +++ b/packages/web-provider/src/mina-network/mina-provider.ts @@ -308,7 +308,6 @@ export class MinaProvider implements IMinaProvider { if (params.data?.origin) { requestOrigin = params.data.origin } - console.log("params, in `request` method:", params) if (await this.vault.isBlocked({ origin: requestOrigin })) { throw this.createProviderRpcError( 4100, diff --git a/packages/web-provider/src/vault-service/vault-service.ts b/packages/web-provider/src/vault-service/vault-service.ts index f3520ca9..514afbfd 100644 --- a/packages/web-provider/src/vault-service/vault-service.ts +++ b/packages/web-provider/src/vault-service/vault-service.ts @@ -27,9 +27,7 @@ export type ZkAppUrl = string export class VaultService implements IVaultService { private static instance: VaultService - private constructor(exampleArg?: boolean) { - console.log("exampleArg: ", exampleArg) - } + private constructor() {} public static getInstance() { if (!VaultService.instance) {