Skip to content
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

Ethereum/Solana: Support additional tokens from info server #826

Merged
merged 4 commits into from
Sep 5, 2024

Conversation

peachbits
Copy link
Contributor

@peachbits peachbits commented Aug 31, 2024

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

none

Description

none

Copy link
Collaborator

@samholmes samholmes left a comment

Choose a reason for hiding this comment

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

I only have questions and comments

src/common/types.ts Show resolved Hide resolved
// Merge token maps
for (const [tokenId, incomingToken] of Object.entries(cleanTokens)) {
if (builtinTokens[tokenId] != null) continue
if (currencyInfo.currencyCode === incomingToken.currencyCode) continue // TODO: Remove after migrating away from currencyCode keyed objects
Copy link
Collaborator

Choose a reason for hiding this comment

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

This TODO comment confuses me. Is this for line 151 or 152?

Comment on lines 152 to 154
const matchingToken = Object.values(builtinTokens).find(
token => token.currencyCode === incomingToken.currencyCode
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

So we don't allow for info server tokens to stomp on our built-in list if a currency code is already in-use. So, info server can only provide additional tokens and no updates to existing token information.

Comment on lines 39 to 55
export const createEvmToken = (
rawToken: unknown
): { tokenId: string; token: EdgeToken } => {
const token = asEdgeToken(rawToken)
const cleanLocation = asMaybeContractLocation(token.networkLocation)
if (
cleanLocation == null ||
!EthereumUtil.isValidAddress(cleanLocation.contractAddress)
) {
throw new Error('ErrorInvalidContractAddress')
}

return {
tokenId: cleanLocation.contractAddress.toLowerCase().replace(/^0x/, ''),
token
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why isn't this function in tokenHelpers.ts? Does it belong in the tools file?

@@ -5,6 +5,7 @@ import { makeMetaTokens } from '../../common/tokenHelpers'
import type { EthereumTools } from '../EthereumTools'
import {
asEthereumInfoPayload,
createEvmToken,
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is it possible to be importing this function from ethereumTypes.ts if it's defined in EthereumTools.ts?

@@ -5,6 +5,7 @@ import { makeMetaTokens } from '../common/tokenHelpers'
import type { SolanaTools } from './SolanaTools'
import {
asSolanaInfoPayload,
createSolanaToken,
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is this possible?

@@ -91,3 +93,7 @@ export const createTokenIdFromContractAddress = (token: EdgeToken): string => {
}
return cleanLocation.contractAddress
}

export const createEvmTokenId = (token: EdgeToken): string => {
return normalizeAddress(createTokenIdFromContractAddress(token))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function is named normalizeAddress yet we're using it to get a "token ID". Weird. Oh well.

@peachbits peachbits merged commit 559188d into master Sep 5, 2024
2 checks passed
@peachbits peachbits deleted the mattthew/info-server-tokens branch September 5, 2024 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants