Skip to content

Commit

Permalink
fix(wallet): remove unnecessary permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Jun 7, 2024
1 parent e578a0e commit e486577
Show file tree
Hide file tree
Showing 12 changed files with 11 additions and 50 deletions.
9 changes: 1 addition & 8 deletions apps/extension/manifest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions packages/features/src/web-connector/routes/web-connector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ export const WebConnectorRoute = () => {
})
window.close()
}
const parsedPayload = JSON.parse(payload) as Record<string, any>
const yamlPayload = yaml.stringify(parsedPayload.data) ?? ""
const parsedPayload = payload
? (JSON.parse(payload) as Record<string, any>)
: {}
const yamlPayload = yaml.stringify(parsedPayload?.data) ?? ""
const userFriendlyPayload = DOMPurify.sanitize(highlight(yamlPayload))
if (!rawWindowId) return null
if (!inputType) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Mina } from "@palladxyz/mina-core"
import type {
ChainHistoryProvider,
TransactionsByAddressesArgs,
TransactionsByHashesArgs,
Tx,
} from "@palladxyz/pallad-core"

Expand Down Expand Up @@ -43,10 +42,7 @@ export const createChainHistoryProvider = (
return convertToTransactionBody(data.data)
}
// TODO: remove txByHashes method
const transactionsByHashes = async (
args: TransactionsByHashesArgs,
): Promise<Tx[]> => {
console.log("args", args)
const transactionsByHashes = async (): Promise<Tx[]> => {
/*const promises = args.ids.map(id => {
const endpoint = `${url}/api/core/transactions/${id}`;
return fetch(endpoint).then(response => response.json());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -75,16 +73,13 @@ export class BlockListenerProvider {
}

private async getAccountInfo(args: AccountInfoArgs): Promise<AccountInfo> {
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")
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -75,16 +73,13 @@ export class BlockListenerProvider {
}

private async getAccountInfo(args: AccountInfoArgs): Promise<AccountInfo> {
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")
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packages/providers/src/open-mina/start-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ function runCommand(command: string): Promise<void> {
console.error(`Stderr: ${stderr}`)
return reject(new Error(stderr))
}
console.log(`Stdout: ${stdout}`)
resolve()
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {
ChainHistoryProvider,
TransactionsByAddressesArgs,
TransactionsByHashesArgs,
Tx,
} from "@palladxyz/pallad-core"

Expand Down Expand Up @@ -44,9 +43,7 @@ export const createChainHistoryProvider = (
return data.result
}

const transactionsByHashes = async (
args: TransactionsByHashesArgs,
): Promise<Tx[]> => {
const transactionsByHashes = async (): Promise<Tx[]> => {
// TODO: make dependency on etherscan
/*const client = createPublicClient({
chain: args.chainInfo,
Expand All @@ -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[]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Mina } from "@palladxyz/mina-core"
import type {
ChainHistoryProvider,
TransactionsByAddressesArgs,
TransactionsByHashesArgs,
Tx,
} from "@palladxyz/pallad-core"

Expand Down Expand Up @@ -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}`)
Expand All @@ -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<Tx[]> => {
console.log("args", args)
const transactionsByHashes = async (): Promise<Tx[]> => {
/*const promises = args.ids.map(id => {
const endpoint = `${url}/api/core/transactions/${id}`;
return fetch(endpoint).then(response => response.json());
Expand Down
3 changes: 0 additions & 3 deletions packages/vault/src/vault/utils/switch-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ 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",
)

ensureAccount(networkName, publicKey)
await setCurrentNetworkName(networkName)
console.log("networkName name in switch network", networkName)

await _syncWallet(networkName)
}
2 changes: 0 additions & 2 deletions packages/vault/src/vault/utils/sync-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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`,
Expand Down
1 change: 0 additions & 1 deletion packages/web-provider/src/mina-network/mina-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions packages/web-provider/src/vault-service/vault-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e486577

Please sign in to comment.