From 4a3db5ae20bf7e510014682fc6e3f9f67a662ba7 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Fri, 5 Jun 2020 07:40:44 +0100 Subject: [PATCH] enforce minimum spend / deposits --- .../dialog/RepostClaimDialogFragment.java | 5 +++ .../browser/dialog/SendTipDialogFragment.java | 6 ++-- .../ui/channel/ChannelFormFragment.java | 3 +- .../browser/ui/wallet/WalletFragment.java | 32 ++++++++++++++----- .../java/io/lbry/browser/utils/Helper.java | 1 + app/src/main/res/values/strings.xml | 1 + 6 files changed, 36 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/dialog/RepostClaimDialogFragment.java b/app/src/main/java/io/lbry/browser/dialog/RepostClaimDialogFragment.java index edd8a1f5..26883447 100644 --- a/app/src/main/java/io/lbry/browser/dialog/RepostClaimDialogFragment.java +++ b/app/src/main/java/io/lbry/browser/dialog/RepostClaimDialogFragment.java @@ -231,6 +231,11 @@ public class RepostClaimDialogFragment extends BottomSheetDialogFragment impleme showError(getString(R.string.insufficient_balance)); return; } + if (bid.doubleValue() < Helper.MIN_DEPOSIT) { + String message = getResources().getQuantityString(R.plurals.min_deposit_required, 2, String.valueOf(Helper.MIN_DEPOSIT)); + showError(message); + return; + } Claim channel = (Claim) channelSpinner.getSelectedItem(); if (channel == null) { diff --git a/app/src/main/java/io/lbry/browser/dialog/SendTipDialogFragment.java b/app/src/main/java/io/lbry/browser/dialog/SendTipDialogFragment.java index 7c9b7a3b..eed10265 100644 --- a/app/src/main/java/io/lbry/browser/dialog/SendTipDialogFragment.java +++ b/app/src/main/java/io/lbry/browser/dialog/SendTipDialogFragment.java @@ -12,7 +12,6 @@ import android.view.ViewGroup; import android.widget.ProgressBar; import android.widget.TextView; -import androidx.core.content.ContextCompat; import androidx.core.text.HtmlCompat; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; @@ -21,7 +20,6 @@ import com.google.android.material.snackbar.Snackbar; import com.google.android.material.textfield.TextInputEditText; import java.math.BigDecimal; -import java.text.DecimalFormat; import io.lbry.browser.MainActivity; import io.lbry.browser.R; @@ -113,6 +111,10 @@ public class SendTipDialogFragment extends BottomSheetDialogFragment implements showError(getString(R.string.insufficient_balance)); return; } + if (amount.doubleValue() < Helper.MIN_SPEND) { + showError(getString(R.string.min_spend_required)); + return; + } SupportCreateTask task = new SupportCreateTask(claim.getClaimId(), amount, true, sendProgress, new GenericTaskHandler() { @Override diff --git a/app/src/main/java/io/lbry/browser/ui/channel/ChannelFormFragment.java b/app/src/main/java/io/lbry/browser/ui/channel/ChannelFormFragment.java index 45e3a9fc..ccb3a609 100644 --- a/app/src/main/java/io/lbry/browser/ui/channel/ChannelFormFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/channel/ChannelFormFragment.java @@ -140,7 +140,6 @@ public class ChannelFormFragment extends BaseFragment implements Context context = getContext(); FlexboxLayoutManager flm1 = new FlexboxLayoutManager(context); FlexboxLayoutManager flm2 = new FlexboxLayoutManager(context); - FlexboxLayoutManager flm3 = new FlexboxLayoutManager(context); addedTagsList = root.findViewById(R.id.form_added_tags); addedTagsList.setLayoutManager(flm1); suggestedTagsList = root.findViewById(R.id.form_suggested_tags); @@ -326,7 +325,7 @@ public class ChannelFormFragment extends BaseFragment implements showError(getString(R.string.please_enter_valid_deposit)); return; } - if (depositAmount == 0) { + if (depositAmount < Helper.MIN_DEPOSIT) { String error = getResources().getQuantityString(R.plurals.min_deposit_required, depositAmount == 1 ? 1 : 2, String.valueOf(Helper.MIN_DEPOSIT)); showError(error); return; diff --git a/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java b/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java index 31b9a687..38245035 100644 --- a/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java @@ -407,6 +407,7 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W private void sendCredits() { // wallet_send task + View view = getView(); String recipientAddress = Helper.getValue(inputSendAddress.getText()); String amountString = Helper.getValue(inputSendAmount.getText()); String amount = null; @@ -414,13 +415,24 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W amount = new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)). format(new BigDecimal(amountString).doubleValue()); } catch (NumberFormatException ex) { - Snackbar.make(getView(), R.string.invalid_amount, Snackbar.LENGTH_LONG). - setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); + if (view != null) { + Snackbar.make(view, R.string.invalid_amount, Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); + } + return; + } + + + double actualSendAmount = Double.valueOf(amount); + if (actualSendAmount < Helper.MIN_SPEND) { + if (view != null) { + Snackbar.make(view, R.string.min_spend_required, Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); + } return; } disableSendControls(); - double actualSendAmount = Double.valueOf(amount); WalletSendTask task = new WalletSendTask(recipientAddress, amount, walletSendProgress, new WalletSendTask.WalletSendHandler() { @Override public void onSuccess() { @@ -428,16 +440,20 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W String message = getResources().getQuantityString( R.plurals.you_sent_credits, sentAmount == 1.0 ? 1 : 2, new DecimalFormat("#,###.##").format(sentAmount)); - Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).show(); - inputSendAddress.setText(null); - inputSendAmount.setText(null); + Helper.setViewText(inputSendAddress, null); + Helper.setViewText(inputSendAmount, null); + if (view != null) { + Snackbar.make(view, message, Snackbar.LENGTH_LONG).show(); + } enableSendControls(); } @Override public void onError(Exception error) { - Snackbar.make(getView(), R.string.send_credit_error, Snackbar.LENGTH_LONG). - setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); + if (view != null) { + Snackbar.make(view, R.string.send_credit_error, Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); + } enableSendControls(); } }); diff --git a/app/src/main/java/io/lbry/browser/utils/Helper.java b/app/src/main/java/io/lbry/browser/utils/Helper.java index 94632710..c8f141c0 100644 --- a/app/src/main/java/io/lbry/browser/utils/Helper.java +++ b/app/src/main/java/io/lbry/browser/utils/Helper.java @@ -70,6 +70,7 @@ public final class Helper { public static final MediaType JSON_MEDIA_TYPE = MediaType.get("application/json; charset=utf-8"); public static final int CONTENT_PAGE_SIZE = 25; public static final double MIN_DEPOSIT = 0.001; + public static final double MIN_SPEND = 0.0001; public static final String PLAIN_CURRENCY_FORMAT_PATTERN = "####.##"; public static final String LBC_CURRENCY_FORMAT_PATTERN = "#,###.##"; public static final String FILE_SIZE_FORMAT_PATTERN = "#,###.#"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 09983f89..b755115f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -329,6 +329,7 @@ Unlock Unlock tips? Are you sure you want to unlock all your tips? + Please enter an amount more than 0.0001 credits. You sent %1$s credit