Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chubby-flowers-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly/mobile": patch
---

🐛 route owner rpc through alchemy
9 changes: 9 additions & 0 deletions src/utils/alchemyChains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as accountKitInfra from "@account-kit/infra";

import type { Chain } from "viem";

export default new Map(
Object.values(accountKitInfra)
.filter((c): c is Chain => typeof c === "object" && "id" in c && typeof c.id === "number")
.map((c) => [c.id, c]),
);
9 changes: 8 additions & 1 deletion src/utils/wagmi/owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ import { http } from "viem";
import * as chains from "viem/chains";
import { createConfig, createStorage, custom, injected } from "wagmi";

import alchemyAPIKey from "@exactly/common/alchemyAPIKey";
import chain from "@exactly/common/generated/chain";

import alchemyChainById from "../alchemyChains";
import publicClient from "../publicClient";

const config = createConfig({
chains: [chain, ...Object.values(chains)],
connectors: [miniAppConnector(), injected()],
transports: {
...Object.fromEntries(Object.values(chains).map((c) => [c.id, http()])),
...Object.fromEntries(
Object.values(chains).map((c) => [
c.id,
http(alchemyChainById.get(c.id)?.rpcUrls.alchemy?.http[0]?.concat(`/${alchemyAPIKey}`)),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There are two concerns with this implementation:

  1. Key Mismatch: The alchemyAPIKey is imported from a module that selects a key based on the current chain.id. Using this single key for all chains in viem/chains will likely result in authentication failures for other networks, as Alchemy keys are typically network-specific or project-specific. Based on common/alchemyAPIKey.ts, different networks have different hardcoded keys.
  2. Robustness: Manual URL construction using concat is fragile. Consider using the alchemy transport factory from @account-kit/infra (as seen in publicClient.ts), which handles URL construction and API key injection more robustly. This centralizes the request logic and prevents potential errors in URL construction, consistent with repository practices.
References
  1. When a value is used to construct a request URL, encode it within the function that makes the request rather than at each call site to centralize the security logic and prevent future omissions.

]),
),
[chain.id]: custom(publicClient),
},
storage: createStorage({ key: "wagmi.owner", storage: AsyncStorage }),
Expand Down
Loading