feat: Add logic to re caculate route for sending a transaction based on networks disabled by the user (#2742)

This commit is contained in:
Khushboo-dev-cpp 2022-07-14 16:22:42 +02:00 committed by GitHub
parent 35c4001e57
commit b2ce92fd41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -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) {

View File

@ -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{