mirror of
https://github.com/status-im/status-go.git
synced 2025-02-10 22:06:36 +00:00
From and to chains added to SendDetails type that can be used on the client side if the sending fails that we can display appropriate ephemeral notifications, saying sending from which chain has failed.
116 lines
4.2 KiB
Go
116 lines
4.2 KiB
Go
package responses
|
|
|
|
import (
|
|
"math/big"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
"github.com/status-im/status-go/errors"
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
"github.com/status-im/status-go/services/wallet/requests"
|
|
"github.com/status-im/status-go/services/wallet/wallettypes"
|
|
)
|
|
|
|
type SendDetails struct {
|
|
Uuid string `json:"uuid"`
|
|
SendType int `json:"sendType"`
|
|
FromAddress types.Address `json:"fromAddress"`
|
|
ToAddress types.Address `json:"toAddress"`
|
|
FromChain uint64 `json:"fromChain"` // this chain should be used only if en error occurred while sending a transaction
|
|
ToChain uint64 `json:"toChain"` // this chain should be used only if en error occurred while sending a transaction
|
|
FromToken string `json:"fromToken"`
|
|
ToToken string `json:"toToken"`
|
|
FromAmount string `json:"fromAmount"` // total amount
|
|
ToAmount string `json:"toAmount"`
|
|
OwnerTokenBeingSent bool `json:"ownerTokenBeingSent"`
|
|
ErrorResponse *errors.ErrorResponse `json:"errorResponse,omitempty"`
|
|
|
|
Username string `json:"username"`
|
|
PublicKey string `json:"publicKey"`
|
|
PackID string `json:"packId"`
|
|
}
|
|
|
|
type SigningDetails struct {
|
|
Address types.Address `json:"address"`
|
|
AddressPath string `json:"addressPath"`
|
|
KeyUid string `json:"keyUid"`
|
|
SignOnKeycard bool `json:"signOnKeycard"`
|
|
Hashes []types.Hash `json:"hashes"`
|
|
}
|
|
|
|
type RouterTransactionsForSigning struct {
|
|
SendDetails *SendDetails `json:"sendDetails"`
|
|
SigningDetails *SigningDetails `json:"signingDetails"`
|
|
}
|
|
|
|
type RouterSentTransaction struct {
|
|
FromAddress types.Address `json:"fromAddress"`
|
|
ToAddress types.Address `json:"toAddress"`
|
|
FromChain uint64 `json:"fromChain"`
|
|
ToChain uint64 `json:"toChain"`
|
|
FromToken string `json:"fromToken"`
|
|
ToToken string `json:"toToken"`
|
|
Amount string `json:"amount"` // amount sent
|
|
AmountIn string `json:"amountIn"` // amount that is "data" of tx (important for erc20 tokens)
|
|
AmountOut string `json:"amountOut"` // amount that will be received
|
|
Hash types.Hash `json:"hash"`
|
|
ApprovalTx bool `json:"approvalTx"`
|
|
}
|
|
|
|
type RouterSentTransactions struct {
|
|
SendDetails *SendDetails `json:"sendDetails"`
|
|
SentTransactions []*RouterSentTransaction `json:"sentTransactions"`
|
|
}
|
|
|
|
func NewRouterSentTransaction(sendArgs *wallettypes.SendTxArgs, hash types.Hash, approvalTx bool) *RouterSentTransaction {
|
|
addr := types.Address{}
|
|
if sendArgs.To != nil {
|
|
addr = *sendArgs.To
|
|
}
|
|
if sendArgs.Value == nil {
|
|
sendArgs.Value = (*hexutil.Big)(big.NewInt(0))
|
|
}
|
|
if sendArgs.ValueIn == nil {
|
|
sendArgs.ValueIn = (*hexutil.Big)(big.NewInt(0))
|
|
}
|
|
if sendArgs.ValueOut == nil {
|
|
sendArgs.ValueOut = (*hexutil.Big)(big.NewInt(0))
|
|
}
|
|
return &RouterSentTransaction{
|
|
FromAddress: sendArgs.From,
|
|
ToAddress: addr,
|
|
FromChain: sendArgs.FromChainID,
|
|
ToChain: sendArgs.ToChainID,
|
|
FromToken: sendArgs.FromTokenID,
|
|
ToToken: sendArgs.ToTokenID,
|
|
Amount: sendArgs.Value.String(),
|
|
AmountIn: sendArgs.ValueIn.String(),
|
|
AmountOut: sendArgs.ValueOut.String(),
|
|
Hash: hash,
|
|
ApprovalTx: approvalTx,
|
|
}
|
|
}
|
|
|
|
func (sd *SendDetails) UpdateFields(inputParams requests.RouteInputParams, fromChain uint64, toChain uint64) {
|
|
sd.SendType = int(inputParams.SendType)
|
|
sd.FromAddress = types.Address(inputParams.AddrFrom)
|
|
sd.ToAddress = types.Address(inputParams.AddrTo)
|
|
sd.FromToken = inputParams.TokenID
|
|
sd.ToToken = inputParams.ToTokenID
|
|
if inputParams.AmountIn != nil {
|
|
sd.FromAmount = inputParams.AmountIn.String()
|
|
}
|
|
if inputParams.AmountOut != nil {
|
|
sd.ToAmount = inputParams.AmountOut.String()
|
|
}
|
|
sd.OwnerTokenBeingSent = inputParams.TokenIDIsOwnerToken
|
|
sd.Username = inputParams.Username
|
|
sd.PublicKey = inputParams.PublicKey
|
|
if inputParams.PackID != nil {
|
|
sd.PackID = inputParams.PackID.String()
|
|
}
|
|
|
|
// Set chain IDs, in case of an error while sending a transaction
|
|
sd.FromChain = fromChain
|
|
sd.ToChain = toChain
|
|
}
|