-
Notifications
You must be signed in to change notification settings - Fork 1
Fix source code not displaying for implicit and deterministic accounts #4
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { GithubDto } from '@/Interfaces/github/github.dto' | ||
| import { useNetwork } from '@/contexts/NetworkContext' | ||
| import { detectNetworkFromAddress } from '@/utils/detectNetwork' | ||
| import { detectNetworkFromAddress, isValidNearAccount } from '@/utils/detectNetwork' | ||
| import { extractGitHubDetails } from '@/utils/extractGithub' | ||
| import { ascii_to_str } from '@/utils/near/ascii_converter' | ||
| import { useRpcUrl } from '@/utils/near/rpc' | ||
|
|
@@ -248,11 +248,8 @@ export default function Contract() { | |
| // Step 1: Detect network from contract address and switch if necessary | ||
| useEffect(() => { | ||
| if (accountId) { | ||
| // Check if the TLD is valid (.near or .testnet) | ||
| const isValidTLD = | ||
| accountId.endsWith('.near') || accountId.endsWith('.testnet') | ||
| if (!isValidTLD) { | ||
| console.log(`Invalid TLD for contract: ${accountId}`) | ||
| if (!isValidNearAccount(accountId)) { | ||
| console.log(`Invalid account ID: ${accountId}`) | ||
| setLoading(false) | ||
| setInvalidTLD(true) | ||
| return | ||
|
Comment on lines
+251
to
255
|
||
|
|
@@ -282,7 +279,8 @@ export default function Contract() { | |
| Invalid contract address: {accountId} | ||
| </Text> | ||
| <Text color="gray.500"> | ||
| Contract addresses must end with .near or .testnet | ||
| Must be a named account (.near/.testnet) or an | ||
| implicit/deterministic account. | ||
| </Text> | ||
| </Stack> | ||
| ) : data ? ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,48 @@ | ||
| import { NetworkType } from '@/contexts/NetworkContext' | ||
|
|
||
| /** | ||
| * Detects the network type from a contract address based on its TLD | ||
| * @param contractAddress The contract address to analyze | ||
| * @returns The detected network type or null if can't be determined | ||
| * Checks whether an address is a valid NEAR implicit-style account: | ||
| * - NEAR implicit account: 64 lowercase hex characters | ||
| * - ETH implicit account: 0x + 40 lowercase hex characters | ||
| * - NEAR deterministic account: 0s + 40 lowercase hex characters | ||
| */ | ||
| export const isImplicitAccount = (address: string): boolean => { | ||
| if (!address) return false | ||
| return ( | ||
| /^[0-9a-f]{64}$/.test(address) || | ||
| /^0x[0-9a-f]{40}$/.test(address) || | ||
| /^0s[0-9a-f]{40}$/.test(address) | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Detects the network type from a contract address based on its TLD. | ||
| * Returns null for implicit/deterministic accounts since they can exist on either network. | ||
| */ | ||
| export const detectNetworkFromAddress = ( | ||
| contractAddress: string | ||
| ): NetworkType | null => { | ||
| if (!contractAddress) return null | ||
|
|
||
| // Check if the address ends with .near (mainnet) or .testnet (testnet) | ||
| if (contractAddress.endsWith('.near')) { | ||
| return 'mainnet' | ||
| } else if (contractAddress.endsWith('.testnet')) { | ||
| return 'testnet' | ||
| } | ||
|
|
||
| // If no specific TLD is found, return null | ||
| // Implicit and deterministic accounts can exist on either network | ||
| return null | ||
|
Comment on lines
+18
to
34
|
||
| } | ||
|
|
||
| /** | ||
| * Checks if a contract address has a valid NEAR TLD (.near or .testnet) | ||
| * @param contractAddress The contract address to check | ||
| * @returns Boolean indicating if the address has a valid TLD | ||
| * Checks if a contract address is a valid NEAR account identifier. | ||
| * Accepts named accounts (.near/.testnet) and implicit/deterministic accounts. | ||
| */ | ||
| export const hasValidTLD = (contractAddress: string): boolean => { | ||
| export const isValidNearAccount = (contractAddress: string): boolean => { | ||
| if (!contractAddress) return false | ||
| return ( | ||
| contractAddress.endsWith('.near') || contractAddress.endsWith('.testnet') | ||
| contractAddress.endsWith('.near') || | ||
| contractAddress.endsWith('.testnet') || | ||
| isImplicitAccount(contractAddress) | ||
| ) | ||
|
Comment on lines
37
to
47
|
||
| } | ||
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.
In this effect, the variable/comment naming still refers to “TLD” (
invalidTLD, “TLD validation”), but the logic now validates the full account ID format (named vs implicit/deterministic). Renaming the state/comment would make the intent clearer and prevent confusion when extending validation further.