-
Notifications
You must be signed in to change notification settings - Fork 2
✨ app: provision alchemy rpc urls across lifi chains #833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@exactly/mobile": patch | ||
| --- | ||
|
|
||
| ✨ provision alchemy rpc urls across lifi chains |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| import { optimism } from "@account-kit/infra"; | ||||||
| import * as infra from "@account-kit/infra"; | ||||||
| import { | ||||||
| ChainType, | ||||||
| config, | ||||||
|
|
@@ -51,7 +51,7 @@ export const lifiTokensOptions = queryOptions({ | |||||
| try { | ||||||
| const { tokens } = await getTokens({ chainTypes: [ChainType.EVM] }); | ||||||
| const allTokens = Object.values(tokens).flat(); | ||||||
| if (chain.id !== optimism.id) return allTokens; | ||||||
| if (chain.id !== infra.optimism.id) return allTokens; | ||||||
| const exa = await getToken(chain.id, "0x1e925De1c68ef83bD98eE3E130eF14a50309C01B").catch((error: unknown) => { | ||||||
| reportError(error); | ||||||
| }); | ||||||
|
|
@@ -91,15 +91,34 @@ export function tokenBalancesOptions(account: Address | undefined) { | |||||
| let configured = false; | ||||||
| function ensureConfig() { | ||||||
| if (configured || chain.testnet || chain.id === anvil.id) return; | ||||||
| const rpcUrls = { | ||||||
| ...Object.values(infra).reduce<Record<number, string[]>>((result, item) => { | ||||||
| if (typeof item !== "object" || !("id" in item) || !("rpcUrls" in item)) return result; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🛡️ Proposed fix- if (typeof item !== "object" || !("id" in item) || !("rpcUrls" in item)) return result;
+ if (!item || typeof item !== "object" || !("id" in item) || !("rpcUrls" in item)) return result;📝 Committable suggestion
Suggested change
|
||||||
| const candidate = item as { id: number; rpcUrls: { alchemy?: { http?: string[] } } }; | ||||||
cruzdanilo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| const alchemyRpcUrl = candidate.rpcUrls.alchemy?.http?.[0]; | ||||||
| if (!alchemyRpcUrl) return result; | ||||||
| result[candidate.id] = [`${alchemyRpcUrl}/${alchemyAPIKey}`]; | ||||||
| return result; | ||||||
| }, {}), | ||||||
| [chain.id]: [publicClient.transport.alchemyRpcUrl], | ||||||
cruzdanilo marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, find and examine the lifi.ts file around line 103
fd -e ts -path "*utils/lifi*" --exclude "*.test.*"Repository: exactly/exa Length of output: 223 🏁 Script executed: # Find publicClient definition
fd -e ts "publicClient" --exclude "*.test.*" --exclude node_modulesRepository: exactly/exa Length of output: 109 🏁 Script executed: # Search for how alchemyRpcUrl is defined or used
rg "alchemyRpcUrl" --type tsRepository: exactly/exa Length of output: 357 🏁 Script executed: # Read the lifi.ts file to see full context around line 103
cat -n src/utils/lifi.ts | head -120 | tail -30Repository: exactly/exa Length of output: 1596 🏁 Script executed: # Read publicClient.ts to understand the transport type
cat -n src/utils/publicClient.tsRepository: exactly/exa Length of output: 487 🏁 Script executed: # Check if there's any guard or conditional before line 103
cat -n src/utils/lifi.ts | sed -n '90,110p'Repository: exactly/exa Length of output: 1132 🏁 Script executed: # Search for alchemy transport typing and alchemyRpcUrl property
rg "alchemyRpcUrl" -B 2 -A 2 --type-listRepository: exactly/exa Length of output: 444 🏁 Script executed: # Check what `@account-kit/infra` exports and how alchemy transport is typed
rg "@account-kit/infra" src/utils/publicClient.tsRepository: exactly/exa Length of output: 130 🏁 Script executed: # Check how alchemyAPIKey is imported and what its default value is
rg "alchemyAPIKey" src/utils/lifi.ts -B 2 -A 2Repository: exactly/exa Length of output: 527 🏁 Script executed: # Find the alchemyAPIKey definition/export
fd -e ts -e js "alchemyAPIKey" --exclude node_modulesRepository: exactly/exa Length of output: 78 🏁 Script executed: # Read the alchemyAPIKey definition
cat -n common/alchemyAPIKey.tsRepository: exactly/exa Length of output: 1036 🏁 Script executed: # Also check for type definitions in publicClient.ts to see if alchemyRpcUrl is properly typed
rg "transport" src/utils/publicClient.ts -B 2 -A 2Repository: exactly/exa Length of output: 198 🏁 Script executed: # Check if line 103 execution is guarded for anvil chain
cat -n src/utils/lifi.ts | sed -n '92,104p'Repository: exactly/exa Length of output: 795 Add a guard to ensure If the alchemy transport doesn't expose the [chain.id]: publicClient.transport.alchemyRpcUrl ? [publicClient.transport.alchemyRpcUrl] : [],Or retrieve the URL from the same |
||||||
| }; | ||||||
|
Comment on lines
+94
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial
The ♻️ Proposed inline refactor- const rpcUrls = {
- ...Object.values(infra).reduce<Record<number, string[]>>((result, item) => {
- if (typeof item !== "object" || !("id" in item) || !("rpcUrls" in item)) return result;
- const candidate = item as { id: number; rpcUrls: { alchemy?: { http?: string[] } } };
- const alchemyRpcUrl = candidate.rpcUrls.alchemy?.http?.[0];
- if (!alchemyRpcUrl) return result;
- result[candidate.id] = [`${alchemyRpcUrl}/${alchemyAPIKey}`];
- return result;
- }, {}),
- [chain.id]: [publicClient.transport.alchemyRpcUrl],
- };
createLifiConfig({
integrator: "exa_app",
apiKey: "4bdb54aa-4f28-4c61-992a-a2fdc87b0a0b.251e33ad-ef5e-40cb-9b0f-52d634b99e8f",
preloadChains: false,
providers: [EVM({ getWalletClient: () => Promise.resolve(publicClient) })],
- rpcUrls,
+ rpcUrls: {
+ ...Object.values(infra).reduce<Record<number, string[]>>((result, item) => {
+ if (typeof item !== "object" || !item || !("id" in item) || !("rpcUrls" in item)) return result;
+ const candidate = item as { id: number; rpcUrls: { alchemy?: { http?: string[] } } };
+ const alchemyRpcUrl = candidate.rpcUrls.alchemy?.http?.[0];
+ if (!alchemyRpcUrl) return result;
+ result[candidate.id] = [`${alchemyRpcUrl}/${alchemyAPIKey}`];
+ return result;
+ }, {}),
+ [chain.id]: [publicClient.transport.alchemyRpcUrl],
+ },
});
As per coding guidelines: "Do not extract a value into a variable or logic into a function unless it is used in two or more places; keep single-use values and functions inline." |
||||||
| createLifiConfig({ | ||||||
| integrator: "exa_app", | ||||||
| apiKey: "4bdb54aa-4f28-4c61-992a-a2fdc87b0a0b.251e33ad-ef5e-40cb-9b0f-52d634b99e8f", | ||||||
cruzdanilo marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| preloadChains: false, | ||||||
| providers: [EVM({ getWalletClient: () => Promise.resolve(publicClient) })], | ||||||
| rpcUrls: { | ||||||
| [optimism.id]: [`${optimism.rpcUrls.alchemy?.http[0]}/${alchemyAPIKey}`], | ||||||
| [chain.id]: [publicClient.transport.alchemyRpcUrl], | ||||||
| }, | ||||||
| rpcUrls, | ||||||
| }); | ||||||
| config.loading = getChains({ chainTypes: [ChainType.EVM] }) | ||||||
| .then((availableChains) => { | ||||||
| const rpcs = config.get().rpcUrls as Partial<Record<number, readonly string[]>>; | ||||||
| config.setChains( | ||||||
| availableChains.map((c) => (rpcs[c.id]?.length ? { ...c, metamask: { ...c.metamask, rpcUrls: [] } } : c)), | ||||||
cruzdanilo marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The code spreads Suggested FixConditionally update the Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||
| ); | ||||||
| }) | ||||||
| .catch((error: unknown) => { | ||||||
| reportError(error); | ||||||
| }); | ||||||
| configured = true; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. race condition: |
||||||
| queryClient.prefetchQuery(lifiTokensOptions).catch(reportError); | ||||||
| queryClient.prefetchQuery(lifiChainsOptions).catch(reportError); | ||||||
|
Comment on lines
+112
to
124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 Duplicate getChains call — config.loading and lifiChainsOptions both fetch the same data The new This is functionally correct but results in two sequential Was this helpful? React with 👍 or 👎 to provide feedback. |
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check
typeof item !== "object"is not sufficient to guard againstnull, becausetypeof nullis'object'. Ifitemisnull, the expression!("id" in item)will throw aTypeError. You should add a check foritem === null.