[SafeSign] Add enhanced SwapInfo struct and deprecate old version (#33170)

* [SafeSign] Add enhanced SwapInfo struct and deprecate old version

* Fix iOS

* review(supermassive): implement unit tests for SwapInfoToValue and ValueToSwapInfo
This commit is contained in:
Anirudha Bose
2026-01-14 09:44:56 +00:00
committed by GitHub
parent a205c2bfa7
commit c1ebdf5e7a
24 changed files with 513 additions and 159 deletions
@@ -409,6 +409,171 @@ std::optional<TransactionReceipt> ValueToTransactionReceipt(
return tx_receipt;
}
std::string EncodeSwapProvider(mojom::SwapProvider provider) {
switch (provider) {
case mojom::SwapProvider::kAuto:
return "AUTO";
case mojom::SwapProvider::kLiFi:
return "LIFI";
case mojom::SwapProvider::kZeroEx:
return "ZERO_EX";
case mojom::SwapProvider::kJupiter:
return "JUPITER";
case mojom::SwapProvider::kSquid:
return "SQUID";
case mojom::SwapProvider::kNearIntents:
return "NEAR_INTENTS";
default:
return "AUTO";
}
}
mojom::SwapProvider DecodeSwapProvider(const std::string& provider_str) {
if (provider_str == "AUTO") {
return mojom::SwapProvider::kAuto;
}
if (provider_str == "LIFI") {
return mojom::SwapProvider::kLiFi;
}
if (provider_str == "ZERO_EX") {
return mojom::SwapProvider::kZeroEx;
}
if (provider_str == "JUPITER") {
return mojom::SwapProvider::kJupiter;
}
if (provider_str == "SQUID") {
return mojom::SwapProvider::kSquid;
}
if (provider_str == "NEAR_INTENTS") {
return mojom::SwapProvider::kNearIntents;
}
return mojom::SwapProvider::kAuto;
}
base::Value::Dict SwapInfoToValue(const mojom::SwapInfoPtr& swap_info) {
base::Value::Dict dict;
if (!swap_info) {
return dict;
}
auto source_coin_str = GetStringFromCoinType(swap_info->source_coin);
if (!source_coin_str) {
return dict;
}
dict.Set("source_coin", *source_coin_str);
dict.Set("source_chain_id", swap_info->source_chain_id);
dict.Set("source_token_address", swap_info->source_token_address);
dict.Set("source_amount", swap_info->source_amount);
auto destination_coin_str =
GetStringFromCoinType(swap_info->destination_coin);
if (!destination_coin_str) {
return dict;
}
dict.Set("destination_coin", *destination_coin_str);
dict.Set("destination_chain_id", swap_info->destination_chain_id);
dict.Set("destination_token_address", swap_info->destination_token_address);
dict.Set("destination_amount", swap_info->destination_amount);
dict.Set("destination_amount_min", swap_info->destination_amount_min);
dict.Set("recipient", swap_info->recipient);
dict.Set("provider", EncodeSwapProvider(swap_info->provider));
return dict;
}
mojom::SwapInfoPtr ValueToSwapInfo(const base::Value::Dict& value) {
auto swap_info = mojom::SwapInfo::New();
const std::string* source_coin_str = value.FindString("source_coin");
if (!source_coin_str) {
return nullptr;
}
auto source_coin = GetCoinTypeFromString(*source_coin_str);
if (!source_coin) {
return nullptr;
}
swap_info->source_coin = *source_coin;
const std::string* source_chain_id = value.FindString("source_chain_id");
if (!source_chain_id) {
return nullptr;
}
swap_info->source_chain_id = *source_chain_id;
const std::string* source_token_address =
value.FindString("source_token_address");
if (!source_token_address) {
return nullptr;
}
swap_info->source_token_address = *source_token_address;
const std::string* source_amount = value.FindString("source_amount");
if (!source_amount) {
return nullptr;
}
swap_info->source_amount = *source_amount;
const std::string* destination_coin_str =
value.FindString("destination_coin");
if (!destination_coin_str) {
return nullptr;
}
auto destination_coin = GetCoinTypeFromString(*destination_coin_str);
if (!destination_coin) {
return nullptr;
}
swap_info->destination_coin = *destination_coin;
const std::string* destination_chain_id =
value.FindString("destination_chain_id");
if (!destination_chain_id) {
return nullptr;
}
swap_info->destination_chain_id = *destination_chain_id;
const std::string* destination_token_address =
value.FindString("destination_token_address");
if (!destination_token_address) {
return nullptr;
}
swap_info->destination_token_address = *destination_token_address;
const std::string* destination_amount =
value.FindString("destination_amount");
if (!destination_amount) {
return nullptr;
}
swap_info->destination_amount = *destination_amount;
// destination_amount_min is optional (only for EXACT_INPUT swaps)
const std::string* destination_amount_min =
value.FindString("destination_amount_min");
swap_info->destination_amount_min =
destination_amount_min ? *destination_amount_min : "";
const std::string* recipient = value.FindString("recipient");
if (!recipient) {
return nullptr;
}
swap_info->recipient = *recipient;
const std::string* provider_str = value.FindString("provider");
if (!provider_str) {
return nullptr;
}
swap_info->provider = DecodeSwapProvider(*provider_str);
return swap_info;
}
mojom::DefaultWallet GetDefaultEthereumWallet(PrefService* prefs) {
return static_cast<brave_wallet::mojom::DefaultWallet>(
prefs->GetInteger(kDefaultEthereumWallet));
@@ -54,6 +54,9 @@ base::Value::Dict TransactionReceiptToValue(
std::optional<TransactionReceipt> ValueToTransactionReceipt(
const base::Value::Dict& value);
base::Value::Dict SwapInfoToValue(const mojom::SwapInfoPtr& swap_info);
mojom::SwapInfoPtr ValueToSwapInfo(const base::Value::Dict& value);
bool IsEndpointUsingBraveWalletProxy(const GURL& url);
base::flat_map<std::string, std::string> MakeBraveServicesKeyHeaders();
@@ -262,6 +262,160 @@ TEST(BraveWalletUtilsUnitTest, TransactionReceiptAndValue) {
EXPECT_EQ(tx_receipt, *tx_receipt_from_value);
}
TEST(BraveWalletUtilsUnitTest, SwapInfoToValue_Basic) {
auto swap_info = mojom::SwapInfo::New();
swap_info->source_coin = mojom::CoinType::ETH;
swap_info->source_chain_id = mojom::kMainnetChainId;
swap_info->source_token_address =
"0x0D8775F648430679A709E98d2b0Cb6250d2887EF";
swap_info->source_amount = "1000000000000000000";
swap_info->destination_coin = mojom::CoinType::ETH;
swap_info->destination_chain_id = mojom::kMainnetChainId;
swap_info->destination_token_address =
"0xdAC17F958D2ee523a2206206994597C13D831ec7";
swap_info->destination_amount = "2000000";
swap_info->destination_amount_min = "1950000";
swap_info->recipient = "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb";
swap_info->provider = mojom::SwapProvider::kZeroEx;
base::Value::Dict value = SwapInfoToValue(swap_info);
// Verify all fields are correctly serialized
EXPECT_EQ(*value.FindString("source_coin"), "ETH");
EXPECT_EQ(*value.FindString("source_chain_id"), mojom::kMainnetChainId);
EXPECT_EQ(*value.FindString("source_token_address"),
"0x0D8775F648430679A709E98d2b0Cb6250d2887EF");
EXPECT_EQ(*value.FindString("source_amount"), "1000000000000000000");
EXPECT_EQ(*value.FindString("destination_coin"), "ETH");
EXPECT_EQ(*value.FindString("destination_chain_id"), mojom::kMainnetChainId);
EXPECT_EQ(*value.FindString("destination_token_address"),
"0xdAC17F958D2ee523a2206206994597C13D831ec7");
EXPECT_EQ(*value.FindString("destination_amount"), "2000000");
EXPECT_EQ(*value.FindString("destination_amount_min"), "1950000");
EXPECT_EQ(*value.FindString("recipient"),
"0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb");
EXPECT_EQ(*value.FindString("provider"), "ZERO_EX");
}
TEST(BraveWalletUtilsUnitTest, SwapInfoToValueAndBack_RoundTrip) {
auto swap_info = mojom::SwapInfo::New();
swap_info->source_coin = mojom::CoinType::SOL;
swap_info->source_chain_id = mojom::kSolanaMainnet;
swap_info->source_token_address =
"So11111111111111111111111111111111111111112";
swap_info->source_amount = "1000000000";
swap_info->destination_coin = mojom::CoinType::SOL;
swap_info->destination_chain_id = mojom::kSolanaMainnet;
swap_info->destination_token_address =
"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
swap_info->destination_amount = "50000000";
swap_info->destination_amount_min = "49000000";
swap_info->recipient = "5tzFkiKscXHK5ZXCGbXZxdw7gTjjD1mBwuoFbhUvuAi9";
swap_info->provider = mojom::SwapProvider::kJupiter;
base::Value::Dict value = SwapInfoToValue(swap_info);
auto swap_info_from_value = ValueToSwapInfo(value);
ASSERT_TRUE(swap_info_from_value);
EXPECT_EQ(swap_info, swap_info_from_value);
}
TEST(BraveWalletUtilsUnitTest, SwapInfoToValue_NullPtr) {
mojom::SwapInfoPtr null_swap_info;
base::Value::Dict value = SwapInfoToValue(null_swap_info);
EXPECT_TRUE(value.empty());
}
TEST(BraveWalletUtilsUnitTest, SwapInfoToValue_DifferentProviders) {
std::vector<mojom::SwapProvider> providers = {
mojom::SwapProvider::kAuto, mojom::SwapProvider::kLiFi,
mojom::SwapProvider::kZeroEx, mojom::SwapProvider::kJupiter,
mojom::SwapProvider::kSquid, mojom::SwapProvider::kNearIntents,
};
for (auto provider : providers) {
auto swap_info = mojom::SwapInfo::New();
swap_info->source_coin = mojom::CoinType::ETH;
swap_info->source_chain_id = mojom::kMainnetChainId;
swap_info->source_token_address = "";
swap_info->source_amount = "1000000000000000000";
swap_info->destination_coin = mojom::CoinType::ETH;
swap_info->destination_chain_id = mojom::kMainnetChainId;
swap_info->destination_token_address = "";
swap_info->destination_amount = "2000000000000000000";
swap_info->destination_amount_min = "";
swap_info->recipient = "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb";
swap_info->provider = provider;
base::Value::Dict value = SwapInfoToValue(swap_info);
auto swap_info_from_value = ValueToSwapInfo(value);
ASSERT_TRUE(swap_info_from_value);
EXPECT_EQ(swap_info->provider, swap_info_from_value->provider);
}
}
TEST(BraveWalletUtilsUnitTest, ValueToSwapInfo_InvalidCoin) {
base::Value::Dict value;
value.Set("source_coin", "INVALID_COIN");
value.Set("source_chain_id", mojom::kMainnetChainId);
value.Set("source_token_address", "");
value.Set("source_amount", "1000000000000000000");
value.Set("destination_coin", "ETH");
value.Set("destination_chain_id", mojom::kMainnetChainId);
value.Set("destination_token_address", "");
value.Set("destination_amount", "2000000000000000000");
value.Set("recipient", "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb");
value.Set("provider", "AUTO");
auto swap_info = ValueToSwapInfo(value);
EXPECT_FALSE(swap_info);
value.Set("source_coin", "ETH");
swap_info = ValueToSwapInfo(value);
EXPECT_TRUE(swap_info);
value.Set("destination_coin", "INVALID_COIN");
swap_info = ValueToSwapInfo(value);
EXPECT_FALSE(swap_info);
}
TEST(BraveWalletUtilsUnitTest, ValueToSwapInfo_MissingRequiredFields) {
// All required fields for mojom::SwapInfo
const char* required_fields[] = {"source_coin",
"source_chain_id",
"source_token_address",
"source_amount",
"destination_coin",
"destination_chain_id",
"destination_token_address",
"destination_amount",
"recipient",
"provider"};
base::Value::Dict base_value;
base_value.Set("source_coin", "ETH");
base_value.Set("source_chain_id", mojom::kMainnetChainId);
base_value.Set("source_token_address", "");
base_value.Set("source_amount", "1000000000000000000");
base_value.Set("destination_coin", "ETH");
base_value.Set("destination_chain_id", mojom::kMainnetChainId);
base_value.Set("destination_token_address", "");
base_value.Set("destination_amount", "2000000000000000000");
base_value.Set("recipient", "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb");
base_value.Set("provider", "AUTO");
// The valid dict should be accepted
EXPECT_TRUE(ValueToSwapInfo(base_value));
for (const auto* field : required_fields) {
base::Value::Dict value = base_value.Clone();
value.Remove(field);
auto swap_info = ValueToSwapInfo(value);
EXPECT_FALSE(swap_info) << "Field missing: " << field;
}
}
TEST(BraveWalletUtilsTest, IsEndpointUsingBraveWalletProxy) {
// Test with valid URLs that should match the proxy domains
EXPECT_TRUE(IsEndpointUsingBraveWalletProxy(
@@ -527,10 +527,10 @@ std::optional<LiFiBridgeData> LiFiBridgeDataDecode(
} // namespace
std::optional<std::tuple<mojom::TransactionType, // tx_type
std::vector<std::string>, // tx_params
std::vector<std::string>, // tx_args
mojom::SwapInfoPtr>> // swap_info
std::optional<std::tuple<mojom::TransactionType, // tx_type
std::vector<std::string>, // tx_params
std::vector<std::string>, // tx_args
mojom::SwapInfoDeprecatedPtr>> // swap_info
GetTransactionInfoFromData(const std::vector<uint8_t>& data) {
if (data.empty() || data == std::vector<uint8_t>{0x0}) {
return std::make_tuple(mojom::TransactionType::ETHSend,
@@ -664,7 +664,7 @@ GetTransactionInfoFromData(const std::vector<uint8_t>& data) {
auto from_asset = decoded_path->front();
auto to_asset = decoded_path->back();
auto swap_info = mojom::SwapInfo::New();
auto swap_info = mojom::SwapInfoDeprecated::New();
swap_info->from_coin = mojom::CoinType::ETH;
// from_chain_id and to_chain_id are filled by caller.
swap_info->from_asset = kNativeEVMAssetContractAddress;
@@ -723,7 +723,7 @@ GetTransactionInfoFromData(const std::vector<uint8_t>& data) {
auto from_asset = decoded_path->front();
auto to_asset = decoded_path->back();
auto swap_info = mojom::SwapInfo::New();
auto swap_info = mojom::SwapInfoDeprecated::New();
// from_chain_id and to_chain_id are filled by caller.
swap_info->from_coin = mojom::CoinType::ETH;
swap_info->from_asset = from_asset;
@@ -774,7 +774,7 @@ GetTransactionInfoFromData(const std::vector<uint8_t>& data) {
return std::nullopt;
}
auto swap_info = mojom::SwapInfo::New();
auto swap_info = mojom::SwapInfoDeprecated::New();
// from_chain_id and to_chain_id are filled by caller.
swap_info->from_coin = mojom::CoinType::ETH;
swap_info->from_asset = from_asset.GetString();
@@ -816,7 +816,7 @@ GetTransactionInfoFromData(const std::vector<uint8_t>& data) {
return std::nullopt;
}
auto swap_info = mojom::SwapInfo::New();
auto swap_info = mojom::SwapInfoDeprecated::New();
// from_chain_id and to_chain_id are filled by caller.
swap_info->from_coin = mojom::CoinType::ETH;
swap_info->from_asset = decoded_calldata.value()[0].GetString();
@@ -913,7 +913,7 @@ GetTransactionInfoFromData(const std::vector<uint8_t>& data) {
}
std::vector<std::string> tx_args;
auto swap_info = mojom::SwapInfo::New();
auto swap_info = mojom::SwapInfoDeprecated::New();
if (selector == kFillOtcOrderForEthSelector) {
// The output of the swap is actually WETH but fillOtcOrderForEth()
@@ -987,7 +987,7 @@ GetTransactionInfoFromData(const std::vector<uint8_t>& data) {
return std::nullopt;
}
auto swap_info = mojom::SwapInfo::New();
auto swap_info = mojom::SwapInfoDeprecated::New();
// from_chain_id and to_chain_id are filled by caller.
swap_info->from_coin = mojom::CoinType::ETH;
swap_info->from_asset = kNativeEVMAssetContractAddress;
@@ -1052,7 +1052,7 @@ GetTransactionInfoFromData(const std::vector<uint8_t>& data) {
return std::nullopt;
}
auto swap_info = mojom::SwapInfo::New();
auto swap_info = mojom::SwapInfoDeprecated::New();
// from_chain_id and to_chain_id are filled by caller.
swap_info->from_coin = mojom::CoinType::ETH;
swap_info->from_asset = swap_data->sending_asset_id;
@@ -1117,7 +1117,7 @@ GetTransactionInfoFromData(const std::vector<uint8_t>& data) {
return std::nullopt;
}
auto swap_info = mojom::SwapInfo::New();
auto swap_info = mojom::SwapInfoDeprecated::New();
// from_chain_id and to_chain_id are filled by caller.
swap_info->from_coin = mojom::CoinType::ETH;
swap_info->from_asset = swap_data->sending_asset_id;
@@ -1196,7 +1196,7 @@ GetTransactionInfoFromData(const std::vector<uint8_t>& data) {
return std::nullopt;
}
auto swap_info = mojom::SwapInfo::New();
auto swap_info = mojom::SwapInfoDeprecated::New();
swap_info->from_coin = mojom::CoinType::ETH;
// from_chain_id is filled in by the caller.
swap_info->from_asset = swap_data->sending_asset_id;
@@ -1260,7 +1260,7 @@ GetTransactionInfoFromData(const std::vector<uint8_t>& data) {
return std::nullopt;
}
auto swap_info = mojom::SwapInfo::New();
auto swap_info = mojom::SwapInfoDeprecated::New();
swap_info->from_coin = mojom::CoinType::ETH;
// from_chain_id is filled in by the caller.
swap_info->from_asset = bridge_data->sending_asset_id;
@@ -1312,7 +1312,7 @@ GetTransactionInfoFromData(const std::vector<uint8_t>& data) {
return std::nullopt;
}
auto swap_info = mojom::SwapInfo::New();
auto swap_info = mojom::SwapInfoDeprecated::New();
swap_info->from_coin = mojom::CoinType::ETH;
// from_chain_id and to_chain_id are filled by caller.
swap_info->from_asset = decoded.value()[0].GetString();
@@ -15,10 +15,10 @@
namespace brave_wallet {
std::optional<std::tuple<mojom::TransactionType, // tx_type
std::vector<std::string>, // tx_params
std::vector<std::string>, // tx_args
mojom::SwapInfoPtr>> // swap_info
std::optional<std::tuple<mojom::TransactionType, // tx_type
std::vector<std::string>, // tx_params
std::vector<std::string>, // tx_args
mojom::SwapInfoDeprecatedPtr>> // swap_info
GetTransactionInfoFromData(const std::vector<uint8_t>& data);
} // namespace brave_wallet
@@ -22,11 +22,11 @@ void TestGetTransactionInfoFromData(
mojom::TransactionType expected_tx_type,
std::vector<std::string> expected_tx_params,
std::vector<std::string> expected_tx_args,
mojom::SwapInfoPtr expected_swap_info = nullptr) {
mojom::SwapInfoDeprecatedPtr expected_swap_info = nullptr) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
auto result = GetTransactionInfoFromData(data);
ASSERT_NE(result, std::nullopt);
@@ -50,7 +50,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataTransfer) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// OK: well-formed ERC20Transfer
@@ -114,7 +114,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataApprove) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// OK: well-formed ERC20Approve
@@ -196,7 +196,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataETHSend) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
ASSERT_TRUE(PrefixedHexStringToBytes("0x0", &data));
@@ -222,7 +222,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataERC721TransferFrom) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// OK: well-formed ERC721TransferFrom
@@ -433,7 +433,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataOther) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
@@ -459,7 +459,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataSellEthForTokenToUniswapV3) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// TXN: WETH → STG
@@ -514,7 +514,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataSellTokenForEthToUniswapV3) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// TXN: RSS3 → USDC → WETH
@@ -574,7 +574,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataSellTokenForTokenToUniswapV3) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// TXN: COW → WETH → USDC
@@ -634,7 +634,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataSellToUniswap) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// TXN: USDC → WETH → LDO
@@ -693,7 +693,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataTransformERC20) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// TXN: ETH → DAI
@@ -810,7 +810,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataFillOtcOrderForETH) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// TXN: USDC → ETH
@@ -899,7 +899,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataFillOtcOrderWithETH) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// TXN: ETH → USDC
@@ -983,7 +983,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataFillOtcOrder) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// TXN: USDC → USDT
@@ -1072,7 +1072,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataCowOrderSellEth) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// TXN: XDAI → USDC
@@ -1142,7 +1142,7 @@ TEST(EthDataParser, GetTransactionInfoFromFilForward) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
ASSERT_TRUE(
@@ -1170,7 +1170,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataLiFiSwapTokensGeneric) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// TXN: token → token
@@ -1394,7 +1394,7 @@ TEST(EthDataParser,
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// TXN: ETH → token
@@ -1505,7 +1505,7 @@ TEST(EthDataParser,
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// TXN: token → ETH
@@ -1612,7 +1612,7 @@ TEST(EthDataParser,
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// TXN: token → token
@@ -1723,7 +1723,7 @@ TEST(
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// Function:
@@ -1892,7 +1892,7 @@ TEST(EthDataParser,
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// Function:
@@ -2076,7 +2076,7 @@ TEST(EthDataParser,
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// Function:
@@ -2162,7 +2162,7 @@ TEST(EthDataParser, GetTransactionInfoFromDataLiFiStartBridgeTokensViaMayan) {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// Function:
@@ -2284,7 +2284,7 @@ TEST(EthDataParser,
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// Function:
@@ -2474,7 +2474,7 @@ TEST(
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// Function:
@@ -2648,7 +2648,7 @@ TEST(
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// Function:
@@ -2902,7 +2902,7 @@ TEST(EthDataParser,
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// Function:
@@ -3057,7 +3057,7 @@ TEST(EthDataParser,
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data;
// Function:
@@ -443,7 +443,7 @@ class EthTxManagerUnitTest : public testing::Test {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
auto tx_info = GetTransactionInfoFromData(data);
ASSERT_NE(tx_info, std::nullopt);
@@ -117,7 +117,7 @@ mojom::TransactionInfoPtr EthTxMeta::ToTransactionInfo() const {
mojom::TransactionType tx_type;
std::vector<std::string> tx_params;
std::vector<std::string> tx_args;
mojom::SwapInfoPtr swap_info;
mojom::SwapInfoDeprecatedPtr swap_info;
std::vector<uint8_t> data{0x0};
if (tx_->data().size() > 0) {
data = tx_->data();
@@ -2619,6 +2619,27 @@ union TxDataUnion {
};
struct SwapInfo {
CoinType source_coin;
string source_chain_id;
string source_token_address;
string source_amount;
CoinType destination_coin;
string destination_chain_id;
// An empty string indicates that the asset could not be reliably determined.
string destination_token_address;
// An empty string indicates that the amount could not be reliably determined.
string destination_amount;
// Populated for EXACT_INPUT swaps
string destination_amount_min;
// An empty string indicates that the recipient is not known.
string recipient;
SwapProvider provider;
};
// Deprecated in favour of SwapInfo
struct SwapInfoDeprecated {
CoinType from_coin;
string from_chain_id;
string from_asset;
@@ -2660,7 +2681,7 @@ struct TransactionInfo {
string? effective_recipient;
bool is_retriable;
SwapInfo? swap_info;
SwapInfoDeprecated? swap_info_deprecated;
};
interface TxServiceObserver {
@@ -90,7 +90,7 @@ export const getMockedTransactionInfo =
},
effectiveRecipient: '0x8b52c24d6e2600bdb8dbb6e8da849ed38ab7e81f',
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
}
}
@@ -544,7 +544,7 @@ SerializableTransactionInfo = {
},
effectiveRecipient: undefined,
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
}
export const mockSolDappSignAllTransactionsRequest: //
@@ -21,30 +21,32 @@ export const useSwapTransactionParser = <
T extends
| Pick<
SerializableTransactionInfo | BraveWallet.TransactionInfo,
'chainId' | 'txType' | 'txDataUnion' | 'swapInfo'
'chainId' | 'txType' | 'txDataUnion' | 'swapInfoDeprecated'
>
| undefined,
>(
transaction: T,
) => {
const { data: sellNetwork } = useGetNetworkQuery(
transaction?.swapInfo?.fromAsset === NATIVE_EVM_ASSET_CONTRACT_ADDRESS
transaction?.swapInfoDeprecated?.fromAsset
=== NATIVE_EVM_ASSET_CONTRACT_ADDRESS
? {
chainId: transaction?.swapInfo.fromChainId,
coin: transaction?.swapInfo.fromCoin,
chainId: transaction?.swapInfoDeprecated.fromChainId,
coin: transaction?.swapInfoDeprecated.fromCoin,
}
: skipToken,
)
const { tokenInfo: sellTokenInfo } = useGetTokenInfo(
transaction?.swapInfo
&& transaction.swapInfo.fromAsset
&& transaction.swapInfo.fromAsset !== NATIVE_EVM_ASSET_CONTRACT_ADDRESS
transaction?.swapInfoDeprecated
&& transaction.swapInfoDeprecated.fromAsset
&& transaction.swapInfoDeprecated.fromAsset
!== NATIVE_EVM_ASSET_CONTRACT_ADDRESS
? {
contractAddress: transaction.swapInfo.fromAsset,
contractAddress: transaction.swapInfoDeprecated.fromAsset,
network: {
chainId: transaction.swapInfo.fromChainId,
coin: transaction.swapInfo.fromCoin,
chainId: transaction.swapInfoDeprecated.fromChainId,
coin: transaction.swapInfoDeprecated.fromCoin,
},
}
: skipToken,
@@ -59,23 +61,25 @@ export const useSwapTransactionParser = <
}, [sellTokenInfo, sellNetwork])
const { data: buyNetwork } = useGetNetworkQuery(
transaction?.swapInfo?.toAsset === NATIVE_EVM_ASSET_CONTRACT_ADDRESS
transaction?.swapInfoDeprecated?.toAsset
=== NATIVE_EVM_ASSET_CONTRACT_ADDRESS
? {
chainId: transaction?.swapInfo.toChainId,
coin: transaction?.swapInfo.toCoin,
chainId: transaction?.swapInfoDeprecated.toChainId,
coin: transaction?.swapInfoDeprecated.toCoin,
}
: skipToken,
)
const { tokenInfo: buyTokenInfo } = useGetTokenInfo(
transaction?.swapInfo
&& transaction.swapInfo.toAsset
&& transaction.swapInfo.toAsset !== NATIVE_EVM_ASSET_CONTRACT_ADDRESS
transaction?.swapInfoDeprecated
&& transaction.swapInfoDeprecated.toAsset
&& transaction.swapInfoDeprecated.toAsset
!== NATIVE_EVM_ASSET_CONTRACT_ADDRESS
? {
contractAddress: transaction.swapInfo.toAsset,
contractAddress: transaction.swapInfoDeprecated.toAsset,
network: {
chainId: transaction.swapInfo.toChainId,
coin: transaction.swapInfo.toCoin,
chainId: transaction.swapInfoDeprecated.toChainId,
coin: transaction.swapInfoDeprecated.toCoin,
},
}
: skipToken,
@@ -89,9 +93,11 @@ export const useSwapTransactionParser = <
return buyTokenInfo
}, [buyTokenInfo, buyNetwork])
const sellAmountWei = new Amount(transaction?.swapInfo?.fromAmount || '')
const buyAmountWei = transaction?.swapInfo?.toAmount
? new Amount(transaction.swapInfo.toAmount)
const sellAmountWei = new Amount(
transaction?.swapInfoDeprecated?.fromAmount || '',
)
const buyAmountWei = transaction?.swapInfoDeprecated?.toAmount
? new Amount(transaction.swapInfoDeprecated.toAmount)
: sellAmountWei
return {
@@ -99,7 +105,7 @@ export const useSwapTransactionParser = <
sellAmountWei,
buyToken,
buyAmountWei,
receiver: transaction?.swapInfo?.receiver || '',
provider: transaction?.swapInfo?.provider,
receiver: transaction?.swapInfoDeprecated?.receiver || '',
provider: transaction?.swapInfoDeprecated?.provider,
}
}
@@ -191,11 +191,11 @@ export const TransactionDetailsModal = ({ onClose, transaction }: Props) => {
const { data: toNetwork } = useGetNetworkQuery(
isBridgeTx
&& transaction.swapInfo?.toChainId
&& transaction.swapInfo.toCoin !== undefined
&& transaction.swapInfoDeprecated?.toChainId
&& transaction.swapInfoDeprecated.toCoin !== undefined
? {
chainId: transaction.swapInfo.toChainId,
coin: transaction.swapInfo.toCoin,
chainId: transaction.swapInfoDeprecated.toChainId,
coin: transaction.swapInfoDeprecated.toCoin,
}
: skipToken,
)
@@ -644,7 +644,9 @@ export const TransactionDetailsModal = ({ onClose, transaction }: Props) => {
<HorizontalSpace space='12px' />
<Button
onClick={onClickViewOnBlockExplorer(
transaction.swapInfo?.provider === 'lifi' ? 'lifi' : 'tx',
transaction.swapInfoDeprecated?.provider === 'lifi'
? 'lifi'
: 'tx',
transaction.txHash,
)}
kind='outline'
@@ -160,11 +160,11 @@ export const PortfolioTransactionItem = React.forwardRef<HTMLDivElement, Props>(
const { data: toNetwork } = useGetNetworkQuery(
isBridge
&& transaction.swapInfo?.toChainId
&& transaction.swapInfo.toCoin !== undefined
&& transaction.swapInfoDeprecated?.toChainId
&& transaction.swapInfoDeprecated.toCoin !== undefined
? {
chainId: transaction.swapInfo.toChainId,
coin: transaction.swapInfo.toCoin,
chainId: transaction.swapInfoDeprecated.toChainId,
coin: transaction.swapInfoDeprecated.toCoin,
}
: skipToken,
)
@@ -131,8 +131,8 @@ export function ConfirmSwapTransaction() {
// set to true once Swap+Send is supported
expectRecipientAddress={false}
isBridgeTx={isBridgeTx}
toChainId={selectedPendingTransaction?.swapInfo?.toChainId}
toCoin={selectedPendingTransaction?.swapInfo?.toCoin}
toChainId={selectedPendingTransaction?.swapInfoDeprecated?.toChainId}
toCoin={selectedPendingTransaction?.swapInfoDeprecated?.toCoin}
/>
<PendingTransactionNetworkFeeAndSettings
@@ -157,8 +157,8 @@ export function ConfirmSwapTransaction() {
const isBridgeTx = selectedPendingTransaction
? isBridgeTransaction(selectedPendingTransaction)
: false
const toChainId = selectedPendingTransaction?.swapInfo?.toChainId
const toCoin = selectedPendingTransaction?.swapInfo?.toCoin
const toChainId = selectedPendingTransaction?.swapInfoDeprecated?.toChainId
const toCoin = selectedPendingTransaction?.swapInfoDeprecated?.toCoin
// Queries
const { buyToken, sellToken, buyAmountWei, sellAmountWei } =
@@ -305,7 +305,9 @@ export function ConfirmSwapTransaction() {
: undefined
}
network={buyAssetNetwork}
receiveAddress={selectedPendingTransaction.swapInfo?.receiver}
receiveAddress={
selectedPendingTransaction.swapInfoDeprecated?.receiver
}
/>
</Card>
@@ -127,11 +127,11 @@ export const TransactionIntent = (props: Props) => {
const { data: bridgeToNetwork } = useGetNetworkQuery(
isBridge
&& transaction.swapInfo?.toChainId
&& transaction.swapInfo.toCoin !== undefined
&& transaction.swapInfoDeprecated?.toChainId
&& transaction.swapInfoDeprecated.toCoin !== undefined
? {
chainId: transaction.swapInfo.toChainId,
coin: transaction.swapInfo.toCoin,
chainId: transaction.swapInfoDeprecated.toChainId,
coin: transaction.swapInfoDeprecated.toCoin,
}
: skipToken,
)
@@ -160,12 +160,12 @@ export const TransactionIntent = (props: Props) => {
const transactionConfirmed =
transaction.txStatus === BraveWallet.TransactionStatus.Confirmed
// Currently we only get transaction.swapInfo.receiver info
// Currently we only get transaction.swapInfoDeprecated.receiver info
// for lifi swaps. Core should also return this value
// for all other providers.
const swapOrBridgeRecipient =
transaction.swapInfo?.provider === 'lifi'
? (transaction.swapInfo?.receiver ?? '')
transaction.swapInfoDeprecated?.provider === 'lifi'
? (transaction.swapInfoDeprecated?.receiver ?? '')
: (txAccount?.address ?? '')
const recipientLabel = getAddressLabel(
@@ -360,7 +360,8 @@ export const TransactionIntent = (props: Props) => {
</Text>
<Button
onClick={onClickViewOnBlockExplorer(
isSwapOrBridge && transaction.swapInfo?.provider === 'lifi'
isSwapOrBridge
&& transaction.swapInfoDeprecated?.provider === 'lifi'
? 'lifi'
: 'tx',
transaction.txHash,
@@ -76,7 +76,7 @@ export const mockTransactionInfo: SerializableTransactionInfo = {
originInfo: mockUniswapOriginInfo,
effectiveRecipient: '0x0d8775f648430679a709e98d2b0cb6250d2887ef',
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
}
export const mockSolanaTransactionInfo: SerializableTransactionInfo = {
@@ -131,7 +131,7 @@ export const mockSolanaTransactionInfo: SerializableTransactionInfo = {
originInfo: mockOriginInfo,
effectiveRecipient: undefined,
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
}
export const mockSOLTXInstructions: SerializableTransactionInfo = {
@@ -242,7 +242,7 @@ export const mockSOLTXInstructions: SerializableTransactionInfo = {
originInfo: mockOriginInfo,
effectiveRecipient: undefined,
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
}
export const mockATAInstruction = {
@@ -351,7 +351,7 @@ export const mockFilSendTransaction: FileCoinTransactionInfo = {
txType: BraveWallet.TransactionType.Other,
effectiveRecipient: mockAccount.address,
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
}
export const mockedErc20ApprovalTransaction = {
@@ -411,7 +411,7 @@ export const mockEthSendTransaction = {
chainId: BraveWallet.MAINNET_CHAIN_ID,
effectiveRecipient: mockEthAccount.accountId.address,
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
}
export const mockBtcSendTransaction = {
@@ -465,7 +465,7 @@ export const mockBtcSendTransaction = {
chainId: BraveWallet.BITCOIN_MAINNET,
effectiveRecipient: mockBtcAccount.accountId.address,
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
}
export const mockZecSendTransaction: SerializableTransactionInfo = {
@@ -518,7 +518,7 @@ export const mockZecSendTransaction: SerializableTransactionInfo = {
chainId: BraveWallet.Z_CASH_MAINNET,
effectiveRecipient: mockZecAccount.accountId.address,
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
}
export const mockERC20TransferTransaction: SerializableTransactionInfo = {
@@ -531,7 +531,7 @@ export const mockERC20TransferTransaction: SerializableTransactionInfo = {
isRetriable: false,
originInfo: mockOriginInfo,
submittedTime: { microseconds: 0 },
swapInfo: undefined,
swapInfoDeprecated: undefined,
txArgs: ['0x0d8775f648430679a709e98d2b0cb6250d2887ef', '0x15ddf09c97b0000'],
txDataUnion: {
ethTxData1559: {
@@ -672,7 +672,7 @@ export const createMockTransactionInfo = (arg: {
}
let txArgs: string[] = []
let swapInfo
let swapInfoDeprecated
switch (true) {
case isERC20Approve: {
@@ -697,7 +697,7 @@ export const createMockTransactionInfo = (arg: {
txBase.txDataUnion.ethTxData1559 = ethTxData
}
case isSwap: {
swapInfo = {
swapInfoDeprecated = {
fromCoin: BraveWallet.CoinType.ETH,
fromChainId: chainId,
fromAsset: sendApproveOrSellAssetContractAddress,
@@ -708,7 +708,7 @@ export const createMockTransactionInfo = (arg: {
toAmount: buyAmount || '',
receiver: toAddress,
provider: 'lifi',
} as BraveWallet.SwapInfo
} as BraveWallet.SwapInfoDeprecated
}
}
@@ -724,7 +724,7 @@ export const createMockTransactionInfo = (arg: {
chainId,
fromAccountId: fromAccount.accountId,
txArgs,
swapInfo,
swapInfoDeprecated,
}
}
@@ -806,7 +806,7 @@ export const getPostConfirmationStatusMockTransaction = (
},
txStatus: transactionStatus,
txType: getMockTransactionType(isSwapOrBridge, transactionType, coin),
swapInfo: isSwapOrBridge
swapInfoDeprecated: isSwapOrBridge
? ({
fromCoin: BraveWallet.CoinType.ETH,
fromChainId: BraveWallet.MAINNET_CHAIN_ID,
@@ -821,7 +821,7 @@ export const getPostConfirmationStatusMockTransaction = (
toAmount: '111111111111111',
receiver: '0x0d8775f648430679a709e98d2b0cb6250d2887ef',
provider: 'lifi',
} as BraveWallet.SwapInfo)
} as BraveWallet.SwapInfoDeprecated)
: undefined,
} as SerializableTransactionInfo
}
@@ -864,7 +864,7 @@ export const mockETHSwapTransaction: BraveWallet.TransactionInfo = {
txType: BraveWallet.TransactionType.ETHSwap,
id: 'mock-eth-swap-tx',
txStatus: BraveWallet.TransactionStatus.Unapproved,
swapInfo: {
swapInfoDeprecated: {
fromAmount: '0xde0b6b3a7640000',
fromAsset: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
fromCoin: BraveWallet.CoinType.ETH,
@@ -895,7 +895,7 @@ export const mockETHNativeTokenSendTransaction = {
originSpec: 'chrome://wallet',
eTldPlusOne: '',
},
swapInfo: undefined,
swapInfoDeprecated: undefined,
txArgs: [],
txHash: '',
txParams: [],
@@ -93,7 +93,7 @@ const transactionDummyData: SerializableTransactionInfo[][] = [
originInfo: mockOriginInfo,
effectiveRecipient: '',
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
},
{
chainId: '',
@@ -132,7 +132,7 @@ const transactionDummyData: SerializableTransactionInfo[][] = [
originInfo: mockOriginInfo,
effectiveRecipient: '',
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
},
{
chainId: '',
@@ -171,7 +171,7 @@ const transactionDummyData: SerializableTransactionInfo[][] = [
originInfo: mockOriginInfo,
effectiveRecipient: '',
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
},
{
chainId: '',
@@ -210,7 +210,7 @@ const transactionDummyData: SerializableTransactionInfo[][] = [
originInfo: mockOriginInfo,
effectiveRecipient: '',
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
},
{
chainId: '',
@@ -249,7 +249,7 @@ const transactionDummyData: SerializableTransactionInfo[][] = [
originInfo: mockOriginInfo,
effectiveRecipient: '',
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
},
],
[
@@ -290,7 +290,7 @@ const transactionDummyData: SerializableTransactionInfo[][] = [
originInfo: mockOriginInfo,
effectiveRecipient: '',
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
},
{
chainId: '',
@@ -329,7 +329,7 @@ const transactionDummyData: SerializableTransactionInfo[][] = [
originInfo: mockOriginInfo,
effectiveRecipient: '',
isRetriable: false,
swapInfo: undefined,
swapInfoDeprecated: undefined,
},
],
]
@@ -172,7 +172,7 @@ describe('getETHSwapTransactionBuyAndSellTokens', () => {
txStatus: BraveWallet.TransactionStatus.Unapproved,
txType: BraveWallet.TransactionType.ETHSwap,
isRetriable: false,
swapInfo: {
swapInfoDeprecated: {
fromCoin: mockBasicAttentionToken.coin,
fromChainId: mockBasicAttentionToken.chainId,
fromAsset: mockBasicAttentionToken.contractAddress,
@@ -181,7 +181,7 @@ describe('getETHSwapTransactionBuyAndSellTokens', () => {
toChainId: mockBitcoinErc20Token.chainId,
toAsset: mockBitcoinErc20Token.contractAddress,
toAmount: '2',
} as BraveWallet.SwapInfo,
} as BraveWallet.SwapInfoDeprecated,
},
nativeAsset: makeNetworkAsset(mockNetwork),
})
+18 -18
View File
@@ -486,7 +486,7 @@ export const getETHSwapTransactionBuyAndSellTokens = ({
} => {
if (
!tx
|| !tx.swapInfo
|| !tx.swapInfoDeprecated
|| tx.txType !== BraveWallet.TransactionType.ETHSwap
) {
return {
@@ -500,19 +500,19 @@ export const getETHSwapTransactionBuyAndSellTokens = ({
}
const sellToken =
tx.swapInfo.fromAsset === NATIVE_EVM_ASSET_CONTRACT_ADDRESS
tx.swapInfoDeprecated.fromAsset === NATIVE_EVM_ASSET_CONTRACT_ADDRESS
? nativeAsset
: findTokenByContractAddress(tx.swapInfo.fromAsset, tokensList)
: findTokenByContractAddress(tx.swapInfoDeprecated.fromAsset, tokensList)
// token not found
// return a "faked" coin (will need to "discover" it later)
|| ({
chainId: tx.swapInfo.fromChainId,
coin: tx.swapInfo.fromCoin,
contractAddress: tx.swapInfo.fromAsset,
chainId: tx.swapInfoDeprecated.fromChainId,
coin: tx.swapInfoDeprecated.fromCoin,
contractAddress: tx.swapInfoDeprecated.fromAsset,
symbol: '???',
isErc20: true,
coingeckoId: UNKNOWN_TOKEN_COINGECKO_ID,
name: tx.swapInfo.fromAsset,
name: tx.swapInfoDeprecated.fromAsset,
logo: 'chrome://erc-token-images/',
tokenId: '',
isErc1155: false,
@@ -522,26 +522,26 @@ export const getETHSwapTransactionBuyAndSellTokens = ({
visible: true,
} as BraveWallet.BlockchainToken)
const sellAmountWei = new Amount(tx.swapInfo.fromAmount)
const sellAmountWei = new Amount(tx.swapInfoDeprecated.fromAmount)
const sellAmount = sellToken
? sellAmountWei.divideByDecimals(sellToken.decimals)
: Amount.empty()
const buyToken =
tx.swapInfo.toAsset === NATIVE_EVM_ASSET_CONTRACT_ADDRESS
tx.swapInfoDeprecated.toAsset === NATIVE_EVM_ASSET_CONTRACT_ADDRESS
? nativeAsset
: tx.swapInfo.toAsset
? findTokenByContractAddress(tx.swapInfo.toAsset, tokensList)
: tx.swapInfoDeprecated.toAsset
? findTokenByContractAddress(tx.swapInfoDeprecated.toAsset, tokensList)
// token not found
// return a "faked" coin (will need to "discover" it later)
|| ({
chainId: tx.swapInfo.toChainId,
coin: tx.swapInfo.toCoin,
contractAddress: tx.swapInfo.toAsset,
chainId: tx.swapInfoDeprecated.toChainId,
coin: tx.swapInfoDeprecated.toCoin,
contractAddress: tx.swapInfoDeprecated.toAsset,
symbol: '???',
isErc20: true,
coingeckoId: UNKNOWN_TOKEN_COINGECKO_ID,
name: tx.swapInfo.toAsset,
name: tx.swapInfoDeprecated.toAsset,
logo: 'chrome://erc-token-images/',
tokenId: '',
isErc1155: false,
@@ -552,8 +552,8 @@ export const getETHSwapTransactionBuyAndSellTokens = ({
} as BraveWallet.BlockchainToken)
: undefined
const buyAmountWei = tx.swapInfo.toAmount
? new Amount(tx.swapInfo.toAmount)
const buyAmountWei = tx.swapInfoDeprecated.toAmount
? new Amount(tx.swapInfoDeprecated.toAmount)
: Amount.empty()
const buyAmount = buyToken
? buyAmountWei.divideByDecimals(buyToken.decimals)
@@ -1444,7 +1444,7 @@ export const isSwapTransaction = (tx: TransactionInfo) => {
}
export const isBridgeTransaction = (tx: TransactionInfo) => {
return tx.swapInfo?.fromChainId !== tx.swapInfo?.toChainId
return tx.swapInfoDeprecated?.fromChainId !== tx.swapInfoDeprecated?.toChainId
}
export const getTransactionFormattedSendCurrencyTotal = ({
@@ -469,7 +469,7 @@ enum TransactionParser {
)
)
case .ethSwap:
guard let swapInfo = transaction.swapInfo
guard let swapInfo = transaction.swapInfoDeprecated
else {
return nil
}
@@ -1429,7 +1429,7 @@ extension BraveWallet.TransactionInfo {
/// Contract address for the from and to token being swapped
var ethSwapTokenContractAddresses: (from: String, to: String)? {
guard txType == .ethSwap, let swapInfo = swapInfo
guard txType == .ethSwap, let swapInfo = swapInfoDeprecated
else { return nil }
return (swapInfo.fromAsset, swapInfo.toAsset)
}
@@ -275,7 +275,7 @@ extension BraveWallet.TransactionInfo {
chainId: BraveWallet.MainnetChainId,
effectiveRecipient: "0x3f2116ef98fcab1a9c3c2d8988e0064ab59acfca",
isRetriable: false,
swapInfo: nil
swapInfoDeprecated: nil
)
}
static var previewConfirmedSwap: BraveWallet.TransactionInfo {
@@ -315,7 +315,7 @@ extension BraveWallet.TransactionInfo {
chainId: BraveWallet.MainnetChainId,
effectiveRecipient: "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
isRetriable: false,
swapInfo: .init(
swapInfoDeprecated: .init(
from: .eth,
fromChainId: BraveWallet.MainnetChainId,
fromAsset: BraveWallet.ethSwapAddress,
@@ -369,7 +369,7 @@ extension BraveWallet.TransactionInfo {
chainId: BraveWallet.MainnetChainId,
effectiveRecipient: BraveWallet.BlockchainToken.previewDaiToken.contractAddress,
isRetriable: false,
swapInfo: nil
swapInfoDeprecated: nil
)
}
/// Sent `mockERC721NFTToken` NFT
@@ -413,7 +413,7 @@ extension BraveWallet.TransactionInfo {
chainId: BraveWallet.MainnetChainId,
effectiveRecipient: "0x3f2116ef98fcab1a9c3c2d8988e0064ab59acfca",
isRetriable: false,
swapInfo: nil
swapInfoDeprecated: nil
)
}
/// Solana System Transfer
@@ -454,7 +454,7 @@ extension BraveWallet.TransactionInfo {
chainId: BraveWallet.SolanaMainnet,
effectiveRecipient: nil, // Currently only available for ETH and FIL
isRetriable: false,
swapInfo: nil
swapInfoDeprecated: nil
)
}
/// Solana Token Transfer
@@ -494,7 +494,7 @@ extension BraveWallet.TransactionInfo {
chainId: BraveWallet.SolanaMainnet,
effectiveRecipient: nil, // Currently only available for ETH and FIL
isRetriable: false,
swapInfo: nil
swapInfoDeprecated: nil
)
}
/// Filecoin Unapproved Send
@@ -526,7 +526,7 @@ extension BraveWallet.TransactionInfo {
chainId: BraveWallet.FilecoinMainnet,
effectiveRecipient: nil,
isRetriable: false,
swapInfo: nil
swapInfoDeprecated: nil
)
/// Bitcoin Unapproved Send
static let mockBTCUnapprovedSend = BraveWallet.TransactionInfo(
@@ -556,7 +556,7 @@ extension BraveWallet.TransactionInfo {
chainId: BraveWallet.BitcoinMainnet,
effectiveRecipient: nil,
isRetriable: false,
swapInfo: nil
swapInfoDeprecated: nil
)
/// Zcash Unapproved Send
static let mockZecUnapprovedSend = BraveWallet.TransactionInfo(
@@ -588,7 +588,7 @@ extension BraveWallet.TransactionInfo {
chainId: BraveWallet.ZCashMainnet,
effectiveRecipient: nil,
isRetriable: false,
swapInfo: nil
swapInfoDeprecated: nil
)
static private func _transactionBase64ToData(_ base64String: String) -> [NSNumber] {
@@ -688,7 +688,7 @@ class AccountActivityStoreTests: XCTestCase {
chainId: BraveWallet.FilecoinMainnet,
effectiveRecipient: nil,
isRetriable: false,
swapInfo: nil
swapInfoDeprecated: nil
)
let transactionCopy = transaction.copy() as! BraveWallet.TransactionInfo
@@ -192,7 +192,7 @@ class TransactionParserTests: XCTestCase {
txArgs: [String] = [],
chainId: String = BraveWallet.MainnetChainId,
effectiveRecipient: String,
swapInfo: BraveWallet.SwapInfo? = nil
swapInfoDeprecated: BraveWallet.SwapInfoDeprecated? = nil
) -> BraveWallet.TransactionInfo {
BraveWallet.TransactionInfo(
id: "1",
@@ -210,7 +210,7 @@ class TransactionParserTests: XCTestCase {
chainId: chainId,
effectiveRecipient: effectiveRecipient,
isRetriable: false,
swapInfo: swapInfo
swapInfoDeprecated: swapInfoDeprecated
)
}
@@ -392,7 +392,7 @@ class TransactionParserTests: XCTestCase {
txType: .ethSwap,
txArgs: [],
effectiveRecipient: transactionData.baseData.to,
swapInfo: .init(
swapInfoDeprecated: .init(
from: .eth,
fromChainId: BraveWallet.MainnetChainId,
fromAsset: BraveWallet.ethSwapAddress,
@@ -477,7 +477,7 @@ class TransactionParserTests: XCTestCase {
txType: .ethSwap,
txArgs: [],
effectiveRecipient: transactionData.baseData.to,
swapInfo: .init(
swapInfoDeprecated: .init(
from: .eth,
fromChainId: BraveWallet.MainnetChainId,
fromAsset: "0x07865c6e87b9f70255377e024ace6630c1eaa37f",