fix(wallet): properly parse multitransaction amounts
This commit is contained in:
parent
ad9ad4026b
commit
60b160997c
|
@ -476,14 +476,18 @@ func getTrInAndOutAmounts(activityType Type, trAmount sql.NullString) (inAmount
|
|||
|
||||
func getMtInAndOutAmounts(dbFromAmount sql.NullString, dbToAmount sql.NullString) (inAmount *hexutil.Big, outAmount *hexutil.Big) {
|
||||
if dbFromAmount.Valid && dbToAmount.Valid {
|
||||
fromAmount, frOk := new(big.Int).SetString(dbFromAmount.String, 16)
|
||||
toAmount, toOk := new(big.Int).SetString(dbToAmount.String, 16)
|
||||
if frOk && toOk {
|
||||
inAmount = (*hexutil.Big)(toAmount)
|
||||
outAmount = (*hexutil.Big)(fromAmount)
|
||||
return
|
||||
fromHexStr := dbFromAmount.String
|
||||
toHexStr := dbToAmount.String
|
||||
if len(fromHexStr) > 2 && len(toHexStr) > 2 {
|
||||
fromAmount, frOk := new(big.Int).SetString(dbFromAmount.String[2:], 16)
|
||||
toAmount, toOk := new(big.Int).SetString(dbToAmount.String[2:], 16)
|
||||
if frOk && toOk {
|
||||
inAmount = (*hexutil.Big)(toAmount)
|
||||
outAmount = (*hexutil.Big)(fromAmount)
|
||||
return
|
||||
}
|
||||
}
|
||||
log.Warn(fmt.Sprintf("could not parse amounts %s %s", dbFromAmount.String, dbToAmount.String))
|
||||
log.Warn(fmt.Sprintf("could not parse amounts %s %s", fromHexStr, toHexStr))
|
||||
} else {
|
||||
log.Warn("invalid transaction amounts")
|
||||
}
|
||||
|
@ -613,6 +617,7 @@ func getActivityEntries(ctx context.Context, db *sql.DB, addresses []eth.Address
|
|||
} else if multiTxID.Valid {
|
||||
mtInAmount, mtOutAmount := getMtInAndOutAmounts(dbMtFromAmount, dbMtToAmount)
|
||||
activityType := multiTransactionTypeToActivityType(transfer.MultiTransactionType(dbMtType.Byte))
|
||||
fmt.Println("getMtInAndOutAmounts", multiTxID.Int64, activityType, mtInAmount, mtOutAmount)
|
||||
entry = NewActivityEntryWithMultiTransaction(transfer.MultiTransactionIDType(multiTxID.Int64),
|
||||
timestamp, activityType, activityStatus, mtInAmount, mtOutAmount)
|
||||
} else {
|
||||
|
|
|
@ -3,10 +3,12 @@ package transfer
|
|||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
eth_common "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/status-im/status-go/services/wallet/common"
|
||||
"github.com/status-im/status-go/services/wallet/testutils"
|
||||
"github.com/status-im/status-go/sqlite"
|
||||
|
@ -72,6 +74,7 @@ func GenerateTestSendMultiTransaction(tr TestTransfer) TestMultiTransaction {
|
|||
FromToken: tr.Token,
|
||||
ToToken: tr.Token,
|
||||
FromAmount: tr.Value,
|
||||
ToAmount: 0,
|
||||
Timestamp: tr.Timestamp,
|
||||
}
|
||||
}
|
||||
|
@ -152,10 +155,13 @@ func InsertTestMultiTransaction(t *testing.T, db *sql.DB, tr *TestMultiTransacti
|
|||
if tr.ToToken == "" {
|
||||
toTokenType = testutils.EthSymbol
|
||||
}
|
||||
fromAmount := (*hexutil.Big)(big.NewInt(tr.FromAmount))
|
||||
toAmount := (*hexutil.Big)(big.NewInt(tr.ToAmount))
|
||||
|
||||
result, err := db.Exec(`
|
||||
INSERT INTO multi_transactions (from_address, from_asset, from_amount, to_address, to_asset, to_amount, type, timestamp
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
tr.FromAddress, fromTokenType, tr.FromAmount, tr.ToAddress, toTokenType, tr.ToAmount, tr.MultiTransactionType, tr.Timestamp)
|
||||
tr.FromAddress, fromTokenType, fromAmount.String(), tr.ToAddress, toTokenType, toAmount.String(), tr.MultiTransactionType, tr.Timestamp)
|
||||
require.NoError(t, err)
|
||||
rowID, err := result.LastInsertId()
|
||||
require.NoError(t, err)
|
||||
|
|
Loading…
Reference in New Issue