fix: buy for test nw first time and dev concerns
This commit is contained in:
@@ -140,7 +140,7 @@ public class CryptoModel {
|
||||
mPendingTxHelper.setAccountInfos(accountInfos);
|
||||
});
|
||||
|
||||
// filter out a separate list of unapproved transactions
|
||||
// Filter out a separate list of unapproved transactions
|
||||
mPendingTransactions =
|
||||
Transformations.map(mPendingTxHelper.mTransactionInfoLd, transactionInfos -> {
|
||||
List<TransactionInfo> pendingTransactionInfo = new ArrayList<>();
|
||||
@@ -288,7 +288,7 @@ public class CryptoModel {
|
||||
return mNetworkModel;
|
||||
}
|
||||
|
||||
public SendModel creteSendModel() {
|
||||
public SendModel createSendModel() {
|
||||
if (mSendModel != null) return mSendModel;
|
||||
mSendModel =
|
||||
new SendModel(mTxService, mKeyringService, mBlockchainRegistry, mJsonRpcService,
|
||||
@@ -335,7 +335,7 @@ public class CryptoModel {
|
||||
mNetworkModel.setAccountInfosFromKeyRingModel(accountInfosFromKeyRingModel);
|
||||
}
|
||||
|
||||
// clear buy send swap model
|
||||
// Clear buy send swap model
|
||||
public void clearBSS() {
|
||||
mSendModel = null;
|
||||
}
|
||||
|
||||
+5
-8
@@ -230,7 +230,7 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity
|
||||
BraveActivity activity = BraveActivity.getBraveActivity();
|
||||
if (activity != null) {
|
||||
mWalletModel = activity.getWalletModel();
|
||||
mSendModel = mWalletModel.getCryptoModel().creteSendModel();
|
||||
mSendModel = mWalletModel.getCryptoModel().createSendModel();
|
||||
}
|
||||
|
||||
mNetworkSpinner = findViewById(R.id.network_spinner);
|
||||
@@ -303,17 +303,13 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity
|
||||
|
||||
NetworkInfo networkInfo = mNetworkAdapter.getNetwork(position);
|
||||
if (networkInfo != null) {
|
||||
if (mActivityType == ActivityType.BUY) {
|
||||
adjustTestFaucetControls(getPerNetworkUiInfo(networkInfo));
|
||||
}
|
||||
|
||||
// Shall be fine regardless of activity type
|
||||
mFromValueText.setText("");
|
||||
mFromValueText.setHint("0");
|
||||
|
||||
mWalletModel.getCryptoModel().getNetworkModel().setNetwork(networkInfo, success -> {
|
||||
if (!success) {
|
||||
Log.e(TAG, "Could not set network");
|
||||
return;
|
||||
}
|
||||
mSelectedNetwork = networkInfo;
|
||||
});
|
||||
@@ -1252,8 +1248,6 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity
|
||||
mValidator = new Validations.SendToAccountAddress();
|
||||
}
|
||||
|
||||
void setCoinType() {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
String fromAccountAddress = mCustomAccountAdapter.getAccountAddressAtPosition(
|
||||
@@ -1563,6 +1557,9 @@ public class BuySendSwapActivity extends BraveWalletBaseActivity
|
||||
&& mSelectedAccount.coin == mSelectedNetwork.coin) {
|
||||
resetSwapFromToAssets();
|
||||
}
|
||||
if (mActivityType == ActivityType.BUY) {
|
||||
adjustTestFaucetControls(getPerNetworkUiInfo(mSelectedNetwork));
|
||||
}
|
||||
});
|
||||
mWalletModel.getKeyringModel().mAccountAllAccountsPair.observe(
|
||||
this, accountInfoListPair -> {
|
||||
|
||||
-1
@@ -79,7 +79,6 @@ public class NetworkSelectorActivity
|
||||
Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
networkSelectorAdapter.setSelectedNetwork(mSelectedNetwork);
|
||||
Log.e(TAG, "Could not set network");
|
||||
}
|
||||
finish();
|
||||
});
|
||||
|
||||
+3
-6
@@ -186,7 +186,7 @@ public class ApproveTxBottomSheetDialogFragment extends BottomSheetDialogFragmen
|
||||
super.onDismiss(dialog);
|
||||
if (mApprovedTxObserver != null) {
|
||||
if (mRejected || mApproved) {
|
||||
// TODO(pav): 28/07/22 rename to callback, it's not an observer
|
||||
// TODO(pav): 28/07/22 rename to callback or delegate, it's not an observer
|
||||
mApprovedTxObserver.onTxApprovedRejected(mApproved, mAccountName, mTxInfo.id);
|
||||
} else {
|
||||
mApprovedTxObserver.onTxPending(mAccountName, mTxInfo.id);
|
||||
@@ -208,10 +208,7 @@ public class ApproveTxBottomSheetDialogFragment extends BottomSheetDialogFragmen
|
||||
((View) parent).getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
JsonRpcService jsonRpcService = getJsonRpcService();
|
||||
KeyringService keyringService = getKeyringService();
|
||||
assert jsonRpcService != null
|
||||
&& keyringService
|
||||
!= null : "json is null=" + (jsonRpcService == null) + "keyring"
|
||||
+ (keyringService != null);
|
||||
assert jsonRpcService != null && keyringService != null;
|
||||
|
||||
TextView networkName = view.findViewById(R.id.network_name);
|
||||
TextView txType = view.findViewById(R.id.tx_type);
|
||||
@@ -371,7 +368,7 @@ public class ApproveTxBottomSheetDialogFragment extends BottomSheetDialogFragmen
|
||||
txService.approveTransaction(mCoinType, mTxInfo.id, (success, error, errorMessage) -> {
|
||||
assert success : "tx is not approved";
|
||||
if (!success) {
|
||||
// error.getProviderError() seems to be cause an unnecessary assertion crash if
|
||||
// error.getProviderError() seems to be cause an assertion crash if
|
||||
// there is no error
|
||||
Utils.warnWhenError(ApproveTxBottomSheetDialogFragment.TAG_FRAGMENT,
|
||||
"approveTransaction", error.getProviderError(), errorMessage);
|
||||
|
||||
+4
-2
@@ -22,8 +22,8 @@ import org.chromium.brave_wallet.mojom.TransactionInfo;
|
||||
import org.chromium.brave_wallet.mojom.TransactionType;
|
||||
import org.chromium.brave_wallet.mojom.TxData;
|
||||
import org.chromium.brave_wallet.mojom.TxData1559;
|
||||
import org.chromium.brave_wallet.mojom.TxDataUnion;
|
||||
import org.chromium.chrome.R;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.TransactionUtils;
|
||||
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
||||
|
||||
public class TxDetailsFragment extends Fragment {
|
||||
@@ -36,7 +36,9 @@ public class TxDetailsFragment extends Fragment {
|
||||
|
||||
private TxDetailsFragment(TransactionInfo txInfo) {
|
||||
mTxInfo = txInfo;
|
||||
mTxData1559 = TransactionUtils.safeEthTxData1559(mTxInfo.txDataUnion);
|
||||
mTxData1559 = mTxInfo.txDataUnion.which() == TxDataUnion.Tag.EthTxData1559
|
||||
? mTxInfo.txDataUnion.getEthTxData1559()
|
||||
: null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -247,10 +247,17 @@ public class ParsedTransaction extends ParsedTransactionFees {
|
||||
final ParsedTransactionFees feeDetails = ParsedTransactionFees.parseTransactionFees(
|
||||
txInfo, selectedNetwork, networkSpotPrice, solFeeEstimatesFee);
|
||||
TxDataUnion txDataUnion = txInfo.txDataUnion;
|
||||
// TxDataUnion has some unnecessary assertion in getter methods that crashes the app
|
||||
TxData1559 txData = TransactionUtils.safeEthTxData1559(txDataUnion);
|
||||
SolanaTxData solTxData = TransactionUtils.safeSolTxData1559(txDataUnion);
|
||||
FilTxData filTxData = TransactionUtils.safeFilTxData1559(txDataUnion);
|
||||
TxData1559 txData = txInfo.txDataUnion.which() == TxDataUnion.Tag.EthTxData1559
|
||||
? txInfo.txDataUnion.getEthTxData1559()
|
||||
: null;
|
||||
SolanaTxData solTxData = txInfo.txDataUnion.which() == TxDataUnion.Tag.SolanaTxData
|
||||
? txInfo.txDataUnion.getSolanaTxData()
|
||||
: null;
|
||||
;
|
||||
FilTxData filTxData = txInfo.txDataUnion.which() == TxDataUnion.Tag.FilTxData
|
||||
? txInfo.txDataUnion.getFilTxData()
|
||||
: null;
|
||||
;
|
||||
|
||||
final boolean isFilTransaction = filTxData != null;
|
||||
final boolean isSPLTransaction = txInfo.txType == TransactionType.SOLANA_SPL_TOKEN_TRANSFER
|
||||
|
||||
+3
-1
@@ -100,7 +100,9 @@ public class ParsedTransactionFees {
|
||||
public static ParsedTransactionFees parseTransactionFees(TransactionInfo txInfo,
|
||||
NetworkInfo selectedNetwork, Double networkSpotPrice, BigInteger solFeeEstimatesFee) {
|
||||
TxDataUnion txDataUnion = txInfo.txDataUnion;
|
||||
TxData1559 txData = TransactionUtils.safeEthTxData1559(txDataUnion);
|
||||
TxData1559 txData = txDataUnion.which() == TxDataUnion.Tag.EthTxData1559
|
||||
? txDataUnion.getEthTxData1559()
|
||||
: null;
|
||||
FilTxData filTxData = null; // TODO: add with FIL
|
||||
final int networkDecimals = selectedNetwork.decimals;
|
||||
final boolean isSolTransaction = txInfo.txType == TransactionType.SOLANA_SYSTEM_TRANSFER
|
||||
|
||||
@@ -89,7 +89,6 @@ public class PendingTxHelper implements TxServiceObserver {
|
||||
mTxService.getAllTransactionInfo(accountInfo.coin, accountInfo.address, allTxContext);
|
||||
}
|
||||
allTxMultiResponse.setWhenAllCompletedAction(() -> {
|
||||
int i = 0;
|
||||
for (AsyncUtils.GetAllTransactionInfoResponseContext allTxContext : allTxContexts) {
|
||||
ArrayList<TransactionInfo> newValue = new ArrayList<TransactionInfo>();
|
||||
for (TransactionInfo txInfo : allTxContext.txInfos) {
|
||||
|
||||
@@ -20,31 +20,4 @@ public class TransactionUtils {
|
||||
else
|
||||
return CoinType.ETH;
|
||||
}
|
||||
|
||||
public static TxData1559 safeEthTxData1559(TxDataUnion txDataUnion) {
|
||||
try {
|
||||
return txDataUnion.getEthTxData1559();
|
||||
} catch (AssertionError e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static SolanaTxData safeSolTxData1559(TxDataUnion txDataUnion) {
|
||||
try {
|
||||
return txDataUnion.getSolanaTxData();
|
||||
} catch (AssertionError e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FilTxData safeFilTxData1559(TxDataUnion txDataUnion) {
|
||||
try {
|
||||
return txDataUnion.getFilTxData();
|
||||
} catch (AssertionError e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,9 +630,13 @@ public class Utils {
|
||||
amount = removeHexPrefix(amount);
|
||||
BigDecimal value = new BigDecimal(amount);
|
||||
|
||||
return value.multiply(new BigDecimal(getDecimalsDepNumber(decimals)))
|
||||
.round(MathContext.UNLIMITED)
|
||||
.longValue();
|
||||
String resStr =
|
||||
value.multiply(new BigDecimal(getDecimalsDepNumber(decimals))).toPlainString();
|
||||
int integerPlaces = resStr.indexOf('.');
|
||||
if (integerPlaces != -1 && (integerPlaces + 9) <= resStr.length()) {
|
||||
resStr = resStr.substring(0, integerPlaces + 9);
|
||||
}
|
||||
return Long.parseLong(resStr);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -50,10 +50,9 @@ public class Validations {
|
||||
if (coinType == CoinType.SOL) {
|
||||
braveWalletService.isBase58EncodedSolanaPubkey(
|
||||
senderAccountAddress, success -> {
|
||||
String responseMsg =
|
||||
resources.getString(R.string.invalid_sol_address);
|
||||
if (success) {
|
||||
responseMsg = "";
|
||||
String responseMsg = "";
|
||||
if (!success) {
|
||||
responseMsg = resources.getString(R.string.invalid_sol_address);
|
||||
}
|
||||
callback.call(responseMsg, success);
|
||||
});
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB |
Reference in New Issue
Block a user