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/order.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart';
abstract class BuyProvider {
@ -32,4 +33,6 @@ abstract class BuyProvider {
Future<Order> findOrderById(String id) => 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 =>
wallet.walletAddresses.primaryAddress ?? wallet.walletAddresses.address;

View file

@ -45,6 +45,31 @@ class MeldProvider extends BuyProvider {
@override
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();
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/order.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/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/themes/theme_base.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/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
@ -57,6 +54,28 @@ class MoonPayProvider extends BuyProvider {
@override
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) {
switch (theme.type) {
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:cw_core/crypto_currency.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
@ -34,6 +35,29 @@ class OnRamperBuyProvider extends BuyProvider {
@override
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 _normalizeCryptoCurrency {

View file

@ -33,6 +33,23 @@ class RobinhoodBuyProvider extends BuyProvider {
@override
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 _apiSecret => secrets.exchangeHelperApiKey;

View file

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

View file

@ -54,87 +54,28 @@ extension ProviderTypeName on ProviderType {
class ProvidersHelper {
static List<ProviderType> getAvailableBuyProviderTypes(WalletType walletType) {
switch (walletType) {
case WalletType.nano:
case WalletType.banano:
return [
ProviderType.askEachTime,
ProviderType.onramper,
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 [];
final providers = <ProviderType>[];
for (final providerType in ProviderType.values) {
final dynamic p = getProviderTypeByType(providerType);
final supportedWalletTypes = p.getSupportedWalletTypes(true) as List<WalletType>;
if (supportedWalletTypes.contains(walletType)) {
providers.add(providerType);
}
}
return providers;
}
static List<ProviderType> getAvailableSellProviderTypes(WalletType walletType) {
switch (walletType) {
case WalletType.bitcoin:
case WalletType.ethereum:
case WalletType.polygon:
return [
ProviderType.askEachTime,
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 [];
final providers = <ProviderType>[];
for (final providerType in ProviderType.values) {
final dynamic p = getProviderTypeByType(providerType);
final supportedWalletTypes = p.getSupportedWalletTypes(false) as List<WalletType>;
if (supportedWalletTypes.contains(walletType)) {
providers.add(providerType);
}
}
return providers;
}
static BuyProvider? getProviderByType(ProviderType type) {
switch (type) {
@ -152,4 +93,21 @@ class ProvidersHelper {
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;
}
}
}