Improve payment withdrawals.

This commit is contained in:
Greyson Parrelli
2022-03-04 12:14:42 -05:00
committed by Alex Hart
parent eae6a971e6
commit 427e73f7fd
7 changed files with 232 additions and 63 deletions

View File

@@ -30,7 +30,6 @@ internal class AccountValues internal constructor(store: KeyValueStore) : Signal
companion object {
private val TAG = Log.tag(AccountValues::class.java)
private const val KEY_SERVICE_PASSWORD = "account.service_password"
private const val KEY_IS_REGISTERED = "account.is_registered"
private const val KEY_REGISTRATION_ID = "account.registration_id"
private const val KEY_FCM_ENABLED = "account.fcm_enabled"
private const val KEY_FCM_TOKEN = "account.fcm_token"
@@ -61,6 +60,8 @@ internal class AccountValues internal constructor(store: KeyValueStore) : Signal
const val KEY_ACI = "account.aci"
@VisibleForTesting
const val KEY_PNI = "account.pni"
@VisibleForTesting
const val KEY_IS_REGISTERED = "account.is_registered"
}
init {

View File

@@ -1,5 +1,6 @@
package org.thoughtcrime.securesms.keyvalue
import androidx.annotation.VisibleForTesting
import androidx.annotation.WorkerThread
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
@@ -36,7 +37,6 @@ internal class PaymentsValues internal constructor(store: KeyValueStore) : Signa
private val TAG = Log.tag(PaymentsValues::class.java)
private const val PAYMENTS_ENTROPY = "payments_entropy"
private const val MOB_PAYMENTS_ENABLED = "mob_payments_enabled"
private const val MOB_LEDGER = "mob_ledger"
private const val PAYMENTS_CURRENT_CURRENCY = "payments_current_currency"
private const val DEFAULT_CURRENCY_CODE = "GBP"
@@ -48,6 +48,9 @@ internal class PaymentsValues internal constructor(store: KeyValueStore) : Signa
private const val SHOW_UPDATE_PIN_INFO_CARD = "mob_payments_show_update_pin_info_card"
private val LARGE_BALANCE_THRESHOLD = Money.mobileCoin(BigDecimal.valueOf(500))
@VisibleForTesting
const val MOB_PAYMENTS_ENABLED = "mob_payments_enabled"
}
private val liveCurrentCurrency: MutableLiveData<Currency> by lazy { MutableLiveData(currentCurrency()) }
@@ -92,16 +95,20 @@ internal class PaymentsValues internal constructor(store: KeyValueStore) : Signa
*/
val paymentsAvailability: PaymentsAvailability
get() {
if (!SignalStore.account().isRegistered ||
!GeographicalRestrictions.e164Allowed(Recipient.self().requireE164())
) {
if (!SignalStore.account().isRegistered) {
return PaymentsAvailability.NOT_IN_REGION
}
return if (FeatureFlags.payments()) {
if (mobileCoinPaymentsEnabled()) {
PaymentsAvailability.WITHDRAW_AND_SEND
} else {
if (GeographicalRestrictions.e164Allowed(SignalStore.account().e164)) {
PaymentsAvailability.WITHDRAW_AND_SEND
} else {
return PaymentsAvailability.WITHDRAW_ONLY
}
} else if (GeographicalRestrictions.e164Allowed(SignalStore.account().e164)) {
PaymentsAvailability.REGISTRATION_AVAILABLE
} else {
PaymentsAvailability.NOT_IN_REGION
}
} else {
if (mobileCoinPaymentsEnabled()) {

View File

@@ -1,16 +1,17 @@
package org.thoughtcrime.securesms.payments;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.BuildConfig;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.Util;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
public final class GeographicalRestrictions {
@@ -18,32 +19,23 @@ public final class GeographicalRestrictions {
private GeographicalRestrictions() {}
private static final Set<Integer> BLACKLIST;
static {
Set<Integer> set = new HashSet<>(BuildConfig.MOBILE_COIN_BLACKLIST.length);
for (int i = 0; i < BuildConfig.MOBILE_COIN_BLACKLIST.length; i++) {
set.add(BuildConfig.MOBILE_COIN_BLACKLIST[i]);
}
BLACKLIST = Collections.unmodifiableSet(set);
}
public static boolean regionAllowed(int regionCode) {
return !BLACKLIST.contains(regionCode);
}
public static boolean e164Allowed(@Nullable String e164) {
try {
int countryCode = PhoneNumberUtil.getInstance()
.parse(e164, null)
.getCountryCode();
return GeographicalRestrictions.regionAllowed(countryCode);
} catch (NumberParseException e) {
Log.w(TAG, e);
if (e164 == null) {
return false;
}
String bareE164 = e164.startsWith("+") ? e164.substring(1) : e164;
return parsePrefixes(FeatureFlags.paymentsCountryBlocklist())
.stream()
.noneMatch(bareE164::startsWith);
}
private static List<String> parsePrefixes(@NonNull String serializedList) {
return Arrays.stream(serializedList.split(","))
.map(v -> v.replaceAll(" ", ""))
.map(String::trim)
.filter(v -> !Util.isEmpty(v))
.collect(Collectors.toList());
}
}

View File

@@ -3,7 +3,6 @@ package org.thoughtcrime.securesms.util;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;
@@ -18,7 +17,6 @@ import org.thoughtcrime.securesms.groups.SelectionLimits;
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
import org.thoughtcrime.securesms.jobs.RemoteConfigRefreshJob;
import org.thoughtcrime.securesms.keyvalue.SignalStore;
import org.thoughtcrime.securesms.keyvalue.StoryValues;
import org.thoughtcrime.securesms.messageprocessingalarm.MessageProcessReceiver;
import java.io.IOException;
@@ -95,6 +93,7 @@ public final class FeatureFlags {
private static final String SOFTWARE_AEC_BLOCKLIST_MODELS = "android.calling.softwareAecBlockList";
private static final String USE_HARDWARE_AEC_IF_OLD = "android.calling.useHardwareAecIfOlderThanApi29";
private static final String USE_AEC3 = "android.calling.useAec3";
private static final String PAYMENTS_COUNTRY_BLOCKLIST = "android.payments.blocklist";
/**
* We will only store remote values for flags in this set. If you want a flag to be controllable
@@ -141,7 +140,8 @@ public final class FeatureFlags {
HARDWARE_AEC_BLOCKLIST_MODELS,
SOFTWARE_AEC_BLOCKLIST_MODELS,
USE_HARDWARE_AEC_IF_OLD,
USE_AEC3
USE_AEC3,
PAYMENTS_COUNTRY_BLOCKLIST
);
@VisibleForTesting
@@ -199,7 +199,8 @@ public final class FeatureFlags {
HARDWARE_AEC_BLOCKLIST_MODELS,
SOFTWARE_AEC_BLOCKLIST_MODELS,
USE_HARDWARE_AEC_IF_OLD,
USE_AEC3
USE_AEC3,
PAYMENTS_COUNTRY_BLOCKLIST
);
/**
@@ -418,6 +419,11 @@ public final class FeatureFlags {
return getBoolean(GROUP_CALL_RINGING, false);
}
/** A comma-separated list of country codes where payments should be disabled. */
public static String paymentsCountryBlocklist() {
return getString(PAYMENTS_COUNTRY_BLOCKLIST, "98,963,53,850,7");
}
/**
* Whether or not to show donor badges in the UI.
*/