mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-25 05:58:42 +01:00
CW-1103:Token Validation Issues (#2327)
* feat(token_validation): Improve flow for adding new tokens across wallets This change: - Implements check to see if a token is already added, preventing duplicates - Triggers dialog warning if its a duplicate token - Takes EVM Chains contract adddress case-insensitivity when making checks for potential scams. * refactor(token_validation): Modify token management flow This change: - Removes duplicate token check during token addition in EVMChainWalletBase. - Introduces a flag to indicate if a token is being edited - Adjusts token addition validation to bypass checks when editing an existing token. * Update lib/src/screens/dashboard/edit_token_page.dart --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
co-authored by
Omar Hatem
parent
4434ad7363
commit
af89603b81
@@ -73,6 +73,7 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
|
||||
|
||||
bool _showDisclaimer = false;
|
||||
bool _disclaimerChecked = false;
|
||||
bool isEditingToken = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -88,6 +89,8 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
|
||||
_tokenSymbolController.text = widget.token!.title;
|
||||
_tokenDecimalController.text = widget.token!.decimals.toString();
|
||||
_tokenIconPathController.text = widget.token?.iconPath ?? '';
|
||||
|
||||
isEditingToken = true;
|
||||
}
|
||||
|
||||
if (widget.initialContractAddress != null) {
|
||||
@@ -200,6 +203,25 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate() &&
|
||||
(!_showDisclaimer || _disclaimerChecked)) {
|
||||
final isTokenAlreadyAdded = isEditingToken
|
||||
? false
|
||||
: await widget.homeSettingsViewModel
|
||||
.checkIfTokenIsAlreadyAdded(_contractAddressController.text);
|
||||
if (isTokenAlreadyAdded) {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return AlertWithOneAction(
|
||||
alertTitle: S.current.warning,
|
||||
alertContent: S.of(context).token_already_exists,
|
||||
buttonText: S.of(context).ok,
|
||||
buttonAction: () => Navigator.of(dialogContext).pop(),
|
||||
);
|
||||
},
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final isWhitelisted = await widget.homeSettingsViewModel
|
||||
.checkIfTokenIsWhitelisted(_contractAddressController.text);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user