chore_: cherry-pick: missing statusgo changes for release (#5737)
* fix_: when preparing a balance map skip chains where cannot get the balance, instead of returning the error * fix_: crash sending collectibles fixed When mapping `MultipathProcessorTxArgs` to `ProcessorInputParams` setting `FromChain` was missed. * fix_: crash when selected token cannot be found is fixed
This commit is contained in:
parent
ab8f1ea709
commit
89662aa300
|
@ -16,6 +16,7 @@ import (
|
||||||
"github.com/status-im/status-go/contracts/community-tokens/collectibles"
|
"github.com/status-im/status-go/contracts/community-tokens/collectibles"
|
||||||
"github.com/status-im/status-go/contracts/erc721"
|
"github.com/status-im/status-go/contracts/erc721"
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
|
"github.com/status-im/status-go/params"
|
||||||
"github.com/status-im/status-go/rpc"
|
"github.com/status-im/status-go/rpc"
|
||||||
"github.com/status-im/status-go/services/wallet/token"
|
"github.com/status-im/status-go/services/wallet/token"
|
||||||
"github.com/status-im/status-go/transactions"
|
"github.com/status-im/status-go/transactions"
|
||||||
|
@ -150,6 +151,9 @@ func (s *ERC721Processor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, signer
|
||||||
|
|
||||||
useSafeTransferFrom := true
|
useSafeTransferFrom := true
|
||||||
inputParams := ProcessorInputParams{
|
inputParams := ProcessorInputParams{
|
||||||
|
FromChain: ¶ms.Network{
|
||||||
|
ChainID: sendArgs.ChainID,
|
||||||
|
},
|
||||||
FromAddr: from,
|
FromAddr: from,
|
||||||
ToAddr: sendArgs.ERC721TransferTx.Recipient,
|
ToAddr: sendArgs.ERC721TransferTx.Recipient,
|
||||||
FromToken: &token.Token{
|
FromToken: &token.Token{
|
||||||
|
|
|
@ -499,7 +499,8 @@ func (r *Router) SuggestedRoutesV2(ctx context.Context, input *RouteInputParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
balanceMap, err := r.getBalanceMapForTokenOnChains(ctx, input, selectedFromChains)
|
balanceMap, err := r.getBalanceMapForTokenOnChains(ctx, input, selectedFromChains)
|
||||||
if err != nil {
|
// return only if there are no balances, otherwise try to resolve the candidates for chains we know the balances for
|
||||||
|
if len(balanceMap) == 0 && err != nil {
|
||||||
return nil, errors.CreateErrorResponseFromError(err)
|
return nil, errors.CreateErrorResponseFromError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,38 +542,57 @@ func (r *Router) getBalanceMapForTokenOnChains(ctx context.Context, input *Route
|
||||||
|
|
||||||
balanceMap = make(map[string]*big.Int)
|
balanceMap = make(map[string]*big.Int)
|
||||||
|
|
||||||
|
chainError := func(chainId uint64, token string, intErr error) {
|
||||||
|
if err == nil {
|
||||||
|
err = fmt.Errorf("chain %d, token %s: %w", chainId, token, intErr)
|
||||||
|
} else {
|
||||||
|
err = fmt.Errorf("%s; chain %d, token %s: %w", err.Error(), chainId, token, intErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, chain := range selectedFromChains {
|
for _, chain := range selectedFromChains {
|
||||||
|
// check token existence
|
||||||
token := input.SendType.FindToken(r.tokenManager, r.collectiblesService, input.AddrFrom, chain, input.TokenID)
|
token := input.SendType.FindToken(r.tokenManager, r.collectiblesService, input.AddrFrom, chain, input.TokenID)
|
||||||
if token == nil {
|
if token == nil {
|
||||||
|
chainError(chain.ChainID, input.TokenID, ErrTokenNotFound)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// check native token existence
|
||||||
|
nativeToken := r.tokenManager.FindToken(chain, chain.NativeCurrencySymbol)
|
||||||
|
if nativeToken == nil {
|
||||||
|
chainError(chain.ChainID, chain.NativeCurrencySymbol, ErrNativeTokenNotFound)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// add token balance for the chain
|
// add token balance for the chain
|
||||||
tokenBalance := big.NewInt(1)
|
var tokenBalance *big.Int
|
||||||
if input.SendType == ERC1155Transfer {
|
if input.SendType == ERC721Transfer {
|
||||||
|
tokenBalance = big.NewInt(1)
|
||||||
|
} else if input.SendType == ERC1155Transfer {
|
||||||
tokenBalance, err = r.getERC1155Balance(ctx, chain, token, input.AddrFrom)
|
tokenBalance, err = r.getERC1155Balance(ctx, chain, token, input.AddrFrom)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.CreateErrorResponseFromError(err)
|
chainError(chain.ChainID, token.Symbol, errors.CreateErrorResponseFromError(err))
|
||||||
}
|
}
|
||||||
} else if input.SendType != ERC721Transfer {
|
} else {
|
||||||
tokenBalance, err = r.getBalance(ctx, chain.ChainID, token, input.AddrFrom)
|
tokenBalance, err = r.getBalance(ctx, chain.ChainID, token, input.AddrFrom)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.CreateErrorResponseFromError(err)
|
chainError(chain.ChainID, token.Symbol, errors.CreateErrorResponseFromError(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
balanceMap[makeBalanceKey(chain.ChainID, token.Symbol)] = tokenBalance
|
// add only if balance is not nil
|
||||||
|
if tokenBalance != nil {
|
||||||
|
balanceMap[makeBalanceKey(chain.ChainID, token.Symbol)] = tokenBalance
|
||||||
|
}
|
||||||
|
|
||||||
// add native token balance for the chain
|
// add native token balance for the chain
|
||||||
nativeToken := r.tokenManager.FindToken(chain, chain.NativeCurrencySymbol)
|
|
||||||
if nativeToken == nil {
|
|
||||||
return nil, ErrNativeTokenNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
nativeBalance, err := r.getBalance(ctx, chain.ChainID, nativeToken, input.AddrFrom)
|
nativeBalance, err := r.getBalance(ctx, chain.ChainID, nativeToken, input.AddrFrom)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.CreateErrorResponseFromError(err)
|
chainError(chain.ChainID, token.Symbol, errors.CreateErrorResponseFromError(err))
|
||||||
|
}
|
||||||
|
// add only if balance is not nil
|
||||||
|
if nativeBalance != nil {
|
||||||
|
balanceMap[makeBalanceKey(chain.ChainID, nativeToken.Symbol)] = nativeBalance
|
||||||
}
|
}
|
||||||
balanceMap[makeBalanceKey(chain.ChainID, nativeToken.Symbol)] = nativeBalance
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue