mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
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.
This commit is contained in:
parent
6fccd784ec
commit
e9cdd60d4b
3 changed files with 11 additions and 9 deletions
|
@ -664,11 +664,6 @@ abstract class EVMChainWalletBase
|
|||
List<Erc20Token> get erc20Currencies => evmChainErc20TokensBox.values.toList();
|
||||
|
||||
Future<void> addErc20Token(Erc20Token token) async {
|
||||
if (evmChainErc20TokensBox.values.any((element) =>
|
||||
element.contractAddress.toLowerCase() == token.contractAddress.toLowerCase())) {
|
||||
throw Exception('Token already exists');
|
||||
}
|
||||
|
||||
String? iconPath;
|
||||
|
||||
if ((token.iconPath == null || token.iconPath!.isEmpty) && !token.isPotentialScam) {
|
||||
|
|
|
@ -73,6 +73,7 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
|
|||
|
||||
bool _showDisclaimer = false;
|
||||
bool _disclaimerChecked = false;
|
||||
bool isEditingToken = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -88,11 +89,15 @@ 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) {
|
||||
_contractAddressController.text = widget.initialContractAddress!;
|
||||
_getTokenInfo();
|
||||
|
||||
isEditingToken = true;
|
||||
}
|
||||
|
||||
_contractAddressFocusNode.addListener(() {
|
||||
|
@ -200,8 +205,10 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
|
|||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate() &&
|
||||
(!_showDisclaimer || _disclaimerChecked)) {
|
||||
final isTokenAlreadyAdded = await widget.homeSettingsViewModel
|
||||
.checkIfTokenIsAlreadyAdded(_contractAddressController.text);
|
||||
final isTokenAlreadyAdded = isEditingToken
|
||||
? false
|
||||
: await widget.homeSettingsViewModel
|
||||
.checkIfTokenIsAlreadyAdded(_contractAddressController.text);
|
||||
if (isTokenAlreadyAdded) {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
|
@ -216,7 +223,7 @@ class _EditTokenPageBodyState extends State<EditTokenPageBody> {
|
|||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
final isWhitelisted = await widget.homeSettingsViewModel
|
||||
.checkIfTokenIsWhitelisted(_contractAddressController.text);
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ abstract class HomeSettingsViewModelBase with Store {
|
|||
}
|
||||
|
||||
@action
|
||||
Future<bool> checkIfTokenIsAlreadyAdded(String contractAddress) async {
|
||||
bool checkIfTokenIsAlreadyAdded(String contractAddress) {
|
||||
if (_balanceViewModel.wallet.type == WalletType.ethereum) {
|
||||
return ethereum!.isTokenAlreadyAdded(_balanceViewModel.wallet, contractAddress);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue