Merge branch 'buy_provider_fixup' of https://github.com/cake-tech/cake_wallet into CW-605-meld-buy

This commit is contained in:
Matthew Fosse 2024-04-04 09:23:56 -07:00
commit 68e3fe60d3
8 changed files with 146 additions and 78 deletions

View file

@ -1,6 +1,7 @@
import 'package:cake_wallet/buy/buy_amount.dart'; import 'package:cake_wallet/buy/buy_amount.dart';
import 'package:cake_wallet/buy/order.dart'; import 'package:cake_wallet/buy/order.dart';
import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
abstract class BuyProvider { abstract class BuyProvider {
@ -32,4 +33,6 @@ abstract class BuyProvider {
Future<Order> findOrderById(String id) => throw UnimplementedError(); Future<Order> findOrderById(String id) => throw UnimplementedError();
Future<BuyAmount> calculateAmount(String amount, String sourceCurrency) => throw UnimplementedError(); Future<BuyAmount> calculateAmount(String amount, String sourceCurrency) => throw UnimplementedError();
List<WalletType> getSupportedWalletTypes(bool isBuy) => throw UnimplementedError();
} }

View file

@ -73,6 +73,23 @@ class DFXBuyProvider extends BuyProvider {
} }
} }
@override
List<WalletType> getSupportedWalletTypes(bool isBuy) {
if (isBuy) {
return [
WalletType.bitcoin,
WalletType.ethereum,
WalletType.polygon,
WalletType.monero,
];
}
return [
WalletType.bitcoin,
WalletType.ethereum,
WalletType.polygon,
];
}
String get walletAddress => String get walletAddress =>
wallet.walletAddresses.primaryAddress ?? wallet.walletAddresses.address; wallet.walletAddresses.primaryAddress ?? wallet.walletAddresses.address;

View file

@ -45,6 +45,31 @@ class MeldProvider extends BuyProvider {
@override @override
String get darkIcon => lightIcon; String get darkIcon => lightIcon;
@override
List<WalletType> getSupportedWalletTypes(bool isBuy) {
if (isBuy) {
return [
WalletType.bitcoin,
WalletType.ethereum,
WalletType.polygon,
WalletType.monero,
WalletType.litecoin,
WalletType.bitcoinCash,
WalletType.nano,
WalletType.banano,
WalletType.solana,
];
}
return [
WalletType.bitcoin,
WalletType.ethereum,
WalletType.polygon,
WalletType.solana,
WalletType.litecoin,
WalletType.bitcoinCash,
];
}
String get currencyCode => walletTypeToCryptoCurrency(wallet.type).title.toLowerCase(); String get currencyCode => walletTypeToCryptoCurrency(wallet.type).title.toLowerCase();
static String convertTheme(ThemeBase theme) { static String convertTheme(ThemeBase theme) {

View file

@ -7,14 +7,11 @@ import 'package:cake_wallet/buy/buy_provider.dart';
import 'package:cake_wallet/buy/buy_provider_description.dart'; import 'package:cake_wallet/buy/buy_provider_description.dart';
import 'package:cake_wallet/buy/order.dart'; import 'package:cake_wallet/buy/order.dart';
import 'package:cake_wallet/exchange/trade_state.dart'; import 'package:cake_wallet/exchange/trade_state.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/palette.dart'; import 'package:cake_wallet/palette.dart';
import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/themes/theme_base.dart'; import 'package:cake_wallet/themes/theme_base.dart';
import 'package:cake_wallet/utils/device_info.dart'; import 'package:cake_wallet/utils/device_info.dart';
import 'package:crypto/crypto.dart';
import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart'; import 'package:cw_core/wallet_type.dart';
@ -57,6 +54,28 @@ class MoonPayProvider extends BuyProvider {
@override @override
String get darkIcon => 'assets/images/moonpay_dark.png'; String get darkIcon => 'assets/images/moonpay_dark.png';
@override
List<WalletType> getSupportedWalletTypes(bool isBuy) {
if (isBuy) {
return [
WalletType.bitcoin,
WalletType.bitcoinCash,
WalletType.litecoin,
WalletType.polygon,
WalletType.ethereum,
WalletType.litecoin,
WalletType.solana,
WalletType.nano,
];
}
return [
WalletType.bitcoin,
WalletType.ethereum,
WalletType.polygon,
WalletType.solana,
];
}
static String themeToMoonPayTheme(ThemeBase theme) { static String themeToMoonPayTheme(ThemeBase theme) {
switch (theme.type) { switch (theme.type) {
case ThemeType.bright: case ThemeType.bright:

View file

@ -7,6 +7,7 @@ import 'package:cake_wallet/themes/extensions/cake_text_theme.dart';
import 'package:cake_wallet/utils/device_info.dart'; import 'package:cake_wallet/utils/device_info.dart';
import 'package:cw_core/crypto_currency.dart'; import 'package:cw_core/crypto_currency.dart';
import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
@ -34,6 +35,29 @@ class OnRamperBuyProvider extends BuyProvider {
@override @override
String get darkIcon => 'assets/images/onramper_dark.png'; String get darkIcon => 'assets/images/onramper_dark.png';
@override
List<WalletType> getSupportedWalletTypes(bool isBuy) {
if (isBuy) {
return [
WalletType.bitcoin,
WalletType.ethereum,
WalletType.polygon,
WalletType.monero,
WalletType.litecoin,
WalletType.bitcoinCash,
WalletType.nano,
WalletType.banano,
WalletType.solana,
];
}
return [
WalletType.bitcoin,
WalletType.ethereum,
WalletType.polygon,
WalletType.solana,
];
}
String get _apiKey => secrets.onramperApiKey; String get _apiKey => secrets.onramperApiKey;
String get _normalizeCryptoCurrency { String get _normalizeCryptoCurrency {

View file

@ -33,6 +33,23 @@ class RobinhoodBuyProvider extends BuyProvider {
@override @override
String get darkIcon => 'assets/images/robinhood_dark.png'; String get darkIcon => 'assets/images/robinhood_dark.png';
@override
List<WalletType> getSupportedWalletTypes(bool isBuy) {
if (isBuy) {
return [
WalletType.bitcoin,
WalletType.ethereum,
WalletType.polygon,
WalletType.litecoin,
WalletType.bitcoinCash,
WalletType.solana,
];
}
return [
WalletType.solana,
];
}
String get _applicationId => secrets.robinhoodApplicationId; String get _applicationId => secrets.robinhoodApplicationId;
String get _apiSecret => secrets.exchangeHelperApiKey; String get _apiSecret => secrets.exchangeHelperApiKey;

View file

@ -45,6 +45,11 @@ class WyreBuyProvider extends BuyProvider {
@override @override
String get darkIcon => 'assets/images/robinhood_dark.png'; String get darkIcon => 'assets/images/robinhood_dark.png';
@override
List<WalletType> getSupportedWalletTypes(bool isBuy) {
return [];
}
String get trackUrl => isTestEnvironment ? _trackTestUrl : _trackProductUrl; String get trackUrl => isTestEnvironment ? _trackTestUrl : _trackProductUrl;
String baseApiUrl; String baseApiUrl;

View file

@ -54,87 +54,28 @@ extension ProviderTypeName on ProviderType {
class ProvidersHelper { class ProvidersHelper {
static List<ProviderType> getAvailableBuyProviderTypes(WalletType walletType) { static List<ProviderType> getAvailableBuyProviderTypes(WalletType walletType) {
switch (walletType) { final providers = <ProviderType>[];
case WalletType.nano: for (final providerType in ProviderType.values) {
case WalletType.banano: final dynamic p = getProviderTypeByType(providerType);
return [ final supportedWalletTypes = p.getSupportedWalletTypes(true) as List<WalletType>;
ProviderType.askEachTime, if (supportedWalletTypes.contains(walletType)) {
ProviderType.onramper, providers.add(providerType);
ProviderType.meld,
];
case WalletType.monero:
return [ProviderType.askEachTime, ProviderType.onramper, ProviderType.dfx];
case WalletType.bitcoin:
case WalletType.polygon:
case WalletType.ethereum:
return [
ProviderType.askEachTime,
ProviderType.onramper,
ProviderType.dfx,
ProviderType.robinhood,
ProviderType.moonpay,
ProviderType.meld,
];
case WalletType.litecoin:
case WalletType.bitcoinCash:
return [
ProviderType.askEachTime,
ProviderType.onramper,
ProviderType.robinhood,
ProviderType.moonpay,
ProviderType.meld,
];
case WalletType.solana:
return [
ProviderType.askEachTime,
ProviderType.onramper,
ProviderType.robinhood,
ProviderType.meld,
];
case WalletType.none:
case WalletType.haven:
return [];
} }
} }
return providers;
}
static List<ProviderType> getAvailableSellProviderTypes(WalletType walletType) { static List<ProviderType> getAvailableSellProviderTypes(WalletType walletType) {
switch (walletType) { final providers = <ProviderType>[];
case WalletType.bitcoin: for (final providerType in ProviderType.values) {
case WalletType.ethereum: final dynamic p = getProviderTypeByType(providerType);
case WalletType.polygon: final supportedWalletTypes = p.getSupportedWalletTypes(false) as List<WalletType>;
return [ if (supportedWalletTypes.contains(walletType)) {
ProviderType.askEachTime, providers.add(providerType);
ProviderType.onramper,
ProviderType.moonpay,
ProviderType.dfx,
ProviderType.meld,
];
case WalletType.litecoin:
case WalletType.bitcoinCash:
return [
ProviderType.askEachTime,
ProviderType.moonpay,
ProviderType.meld,
];
case WalletType.solana:
return [
ProviderType.askEachTime,
ProviderType.onramper,
ProviderType.robinhood,
ProviderType.moonpay,
ProviderType.meld,
];
case WalletType.nano:
return [
ProviderType.meld,
];
case WalletType.banano:
case WalletType.monero:
case WalletType.none:
case WalletType.haven:
return [];
} }
} }
return providers;
}
static BuyProvider? getProviderByType(ProviderType type) { static BuyProvider? getProviderByType(ProviderType type) {
switch (type) { switch (type) {
@ -152,4 +93,21 @@ class ProvidersHelper {
return null; return null;
} }
} }
static Type? getProviderTypeByType(ProviderType type) {
switch (type) {
case ProviderType.robinhood:
return RobinhoodBuyProvider;
case ProviderType.dfx:
return DFXBuyProvider;
case ProviderType.onramper:
return OnRamperBuyProvider;
case ProviderType.moonpay:
return MoonPayProvider;
case ProviderType.meld:
return MeldProvider;
case ProviderType.askEachTime:
return null;
}
}
} }