-
Notifications
You must be signed in to change notification settings - Fork 269
Disallow unsupported FIO assets #5664
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
Conversation
src/util/FioValidation.ts
Outdated
* Validate if an Edge asset can be converted to FIO codes using the whitelist | ||
* TODO: Integrate into the rest of FIO functionality | ||
*/ | ||
export const validateFioAsset = ( |
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.
This should move to fioConstants.ts
, and should use the same logic of const fioAssets = infoServerData.rollup?.fioAssets ?? FIO_ASSET_MAP
. That way it still works if the info server is down. The info server data is supposed to be supplemental to stuff baked in the app.
Indeed, the logic could just be added to tokenIdToFioCode
, which would be edited to return | undefined
. Then we know any place we might send and Edge currency to Fio-land it's actually something Fio supports.
If that's a big change, then just moving this to the right file would be enough for the merge.
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.
Yeah it was intentionally separated because moving to the existing fio<>asset utils had a lot of fallout
1c32f15
to
ece3fcd
Compare
This change doesn't cover all situations, but at least prevents new FIO actions from using unsupported assets.
ece3fcd
to
48ec0ad
Compare
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.
Bug: Inconsistent Token Validation Functions
The new validateFioAsset
function is inconsistent with the existing tokenIdToFioCode
function. validateFioAsset
only checks fioAsset.tokenCodes?.[tokenId]
for tokens, returning isValid: false
if not explicitly mapped. However, tokenIdToFioCode
includes a fallback to currencyConfig.allTokens[tokenId]?.currencyCode
for tokens not in the special mapping. This makes validateFioAsset
more restrictive, especially since the updated FIO_ASSET_MAP
has fewer explicit tokenCodes
. Consequently, validateFioAsset
may reject tokens that tokenIdToFioCode
can successfully convert, leading to inconsistent behavior (e.g., valid tokens being filtered out in the UI).
src/constants/FioConstants.ts#L186-L231
edge-react-gui/src/constants/FioConstants.ts
Lines 186 to 231 in 48ec0ad
*/ | |
export const validateFioAsset = ( | |
currencyConfig: EdgeCurrencyConfig, | |
tokenId: EdgeTokenId | |
): FioValidationResult => { | |
const fioAssets = infoServerData.rollup?.fioAssets ?? FIO_ASSET_MAP | |
const { pluginId } = currencyConfig.currencyInfo | |
// Check if this plugin is supported | |
const fioAsset = fioAssets[pluginId] | |
if (fioAsset == null) { | |
return { | |
isValid: false, | |
error: `${currencyConfig.currencyInfo.displayName} is not supported by FIO Protocol` | |
} | |
} | |
const fioChainCode = fioAsset.chainCode | |
// For native assets (tokenId is null) | |
if (tokenId == null) { | |
return { | |
isValid: true, | |
fioChainCode, | |
fioTokenCode: fioChainCode | |
} | |
} | |
// For tokens, check if the token is in the whitelist | |
const fioTokenCode = fioAsset.tokenCodes?.[tokenId] | |
if (fioTokenCode == null) { | |
const tokenInfo = currencyConfig.allTokens[tokenId] | |
const tokenName = | |
tokenInfo?.displayName ?? tokenInfo?.currencyCode ?? tokenId | |
return { | |
isValid: false, | |
error: `${tokenName} is not supported by FIO Protocol` | |
} | |
} | |
return { | |
isValid: true, | |
fioChainCode, | |
fioTokenCode | |
} | |
} |
Was this report helpful? Give feedback by reacting with 👍 or 👎
This change doesn't cover all situations, but at least prevents new FIO actions from using unsupported assets.
CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
noneRequirements
If you have made any visual changes to the GUI. Make sure you have: