From f17bd07d67f00f19c59a55c37f4d142a10795985 Mon Sep 17 00:00:00 2001 From: pokkst Date: Fri, 16 Sep 2022 23:30:46 -0500 Subject: [PATCH] Parse URIs for amount and address --- .../dialog/SendBottomSheetDialog.java | 28 +++++++++++++++---- .../com/m2049r/xmrwallet/util/Constants.java | 3 ++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/m2049r/xmrwallet/fragment/dialog/SendBottomSheetDialog.java b/app/src/main/java/com/m2049r/xmrwallet/fragment/dialog/SendBottomSheetDialog.java index 454f95d..e312cc0 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/fragment/dialog/SendBottomSheetDialog.java +++ b/app/src/main/java/com/m2049r/xmrwallet/fragment/dialog/SendBottomSheetDialog.java @@ -29,8 +29,10 @@ import com.m2049r.xmrwallet.model.PendingTransaction; import com.m2049r.xmrwallet.model.Wallet; import com.m2049r.xmrwallet.service.BalanceService; import com.m2049r.xmrwallet.service.TxService; +import com.m2049r.xmrwallet.util.Constants; import com.m2049r.xmrwallet.util.Helper; +import java.util.HashMap; import java.util.List; public class SendBottomSheetDialog extends BottomSheetDialogFragment { @@ -234,14 +236,30 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment { } private void pasteAddress(String address) { - String modifiedAddress = address.replace("monero:", "").split("\\?")[0]; - boolean isValid = Wallet.isAddressValid(modifiedAddress); + HashMap params = new HashMap<>(); + String[] uriParts = address.replace(Constants.URI_PREFIX, "").split("\\?"); + String finalAddress = uriParts[0]; + String queryParams = ""; + if(uriParts.length > 1) { + queryParams = uriParts[1]; + String[] queryParts = queryParams.split("&"); + for (String param : queryParts) { + String[] paramParts = param.split("="); + String variable = paramParts[0]; + String value = paramParts[1]; + params.put(variable, value); + } + } + boolean isValid = Wallet.isAddressValid(finalAddress); if (isValid) { - addressEditText.setText(modifiedAddress); + addressEditText.setText(finalAddress); + if(!params.isEmpty()) { + if(params.containsKey(Constants.URI_ARG_AMOUNT)) { + amountEditText.setText(params.get(Constants.URI_ARG_AMOUNT)); + } + } } else { Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show(); } } - - } \ No newline at end of file diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/Constants.java b/app/src/main/java/com/m2049r/xmrwallet/util/Constants.java index c0f0679..114cd4e 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/Constants.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/Constants.java @@ -7,4 +7,7 @@ public class Constants { public static final String PREF_USES_TOR = "pref_uses_tor"; public static final String PREF_NIGHT_MODE = "pref_night_mode"; public static final String PREF_PROXY = "pref_proxy"; + + public static final String URI_PREFIX = "monero:"; + public static final String URI_ARG_AMOUNT = "tx_amount"; }