From b2ce92fd41a3b899749e2ed2ebd94ec8d4e1859f Mon Sep 17 00:00:00 2001 From: Khushboo-dev-cpp <60327365+Khushboo-dev-cpp@users.noreply.github.com> Date: Thu, 14 Jul 2022 16:22:42 +0200 Subject: [PATCH] feat: Add logic to re caculate route for sending a transaction based on networks disabled by the user (#2742) --- services/wallet/api.go | 4 ++-- services/wallet/router.go | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/services/wallet/api.go b/services/wallet/api.go index 21da81824..65f8f97d0 100644 --- a/services/wallet/api.go +++ b/services/wallet/api.go @@ -323,9 +323,9 @@ func (api *API) GetTransactionEstimatedTime(ctx context.Context, chainID uint64, return api.s.feesManager.transactionEstimatedTime(ctx, chainID, maxFeePerGas), nil } -func (api *API) GetSuggestedRoutes(ctx context.Context, account common.Address, amount float64, tokenSymbol string) (*SuggestedRoutes, error) { +func (api *API) GetSuggestedRoutes(ctx context.Context, account common.Address, amount float64, tokenSymbol string, disabledChainIDs []uint64) (*SuggestedRoutes, error) { log.Debug("call to GetSuggestedRoutes") - return api.router.suggestedRoutes(ctx, account, amount, tokenSymbol) + return api.router.suggestedRoutes(ctx, account, amount, tokenSymbol, disabledChainIDs) } func (api *API) GetDerivedAddressesForPath(ctx context.Context, password string, derivedFrom string, path string, pageSize int, pageNumber int) ([]*DerivedAddress, error) { diff --git a/services/wallet/router.go b/services/wallet/router.go index b545d9b1b..70839f77c 100644 --- a/services/wallet/router.go +++ b/services/wallet/router.go @@ -49,7 +49,7 @@ func (r *Router) suitableTokenExists(ctx context.Context, network *params.Networ return false, nil } -func (r *Router) suggestedRoutes(ctx context.Context, account common.Address, amount float64, tokenSymbol string) (*SuggestedRoutes, error) { +func (r *Router) suggestedRoutes(ctx context.Context, account common.Address, amount float64, tokenSymbol string, disabledChainIDs []uint64) (*SuggestedRoutes, error) { areTestNetworksEnabled, err := r.s.accountsDB.GetTestNetworksEnabled() if err != nil { return nil, err @@ -71,6 +71,19 @@ func (r *Router) suggestedRoutes(ctx context.Context, account common.Address, am continue } + networkFound := false + for _, chainID := range disabledChainIDs { + networkFound = false + if chainID == network.ChainID { + networkFound = true + break + } + } + // This is network cannot be used as a suggestedRoute as the user has disabled it + if networkFound { + continue + } + group.Add(func(c context.Context) error { if tokenSymbol == network.NativeCurrencySymbol { tokens := []*Token{&Token{