all the needed changes

This commit is contained in:
Matthew Fosse 2024-04-08 09:38:01 -07:00
parent 95cbba2282
commit cde79a74be
9 changed files with 71 additions and 68 deletions

View file

@ -1 +0,0 @@
<svg width="318" height="99" fill="none" xmlns="http://www.w3.org/2000/svg"><path opacity=".7" d="M46.928 98.35L17.375 81.29V61.223L46.928 78.28v20.068z" fill="url(#paint0_linear)"/><path opacity=".7" d="M46.928 98.35L76.48 81.29V61.223L46.928 78.28v20.068z" fill="url(#paint1_linear)"/><path opacity=".7" d="M93.869 17.058v34.13L76.48 61.223v-34.13l17.388-10.035z" fill="url(#paint2_linear)"/><path d="M93.869 17.058L64.316 0 46.928 10.034 76.48 27.092l17.388-10.034z" fill="url(#paint3_linear)"/><path d="M0 17.058L29.553 0l17.374 10.034-29.553 17.058L0 17.059z" fill="#F969D3"/><path opacity=".7" d="M0 17.058v34.13l17.374 10.035v-34.13L0 17.057z" fill="url(#paint4_linear)"/><path d="M127.732 75.506h10.278V51.15c0-6.996 3.627-9.846 8.636-9.846 4.923 0 8.637 2.937 8.637 9.846v24.355h10.277V51.15c0-6.91 3.627-9.846 8.55-9.846 5.009 0 8.636 2.85 8.636 9.846v24.355h10.278V51.15c0-13.387-7.773-19.432-17.878-19.432-6.477 0-11.745 2.677-14.768 7.686-3.109-5.009-8.377-7.686-14.768-7.686-10.105 0-17.878 6.045-17.878 19.432v24.355zM222.691 76.628c10.105 0 17.878-5.268 21.073-13.386h-10.968c-2.159 2.764-5.527 4.059-10.105 4.059-6.045 0-10.795-3.282-12.177-9.5h34.977v-3.627c0-12.955-9.327-22.455-22.8-22.455s-22.973 9.5-22.973 22.455c0 12.954 9.5 22.454 22.973 22.454zm-11.918-27.032c1.641-5.613 6.132-8.55 11.918-8.55 5.614 0 10.278 2.85 11.919 8.55h-23.837zM253.687 75.506h10.277V14.187h-10.277v61.319zM295.226 76.628c13.386 0 22.714-8.981 22.714-22.8V14.187h-10.278V39.06c-3.023-4.75-8.118-7.341-14.25-7.341-10.364 0-21.246 7.427-21.246 22.023 0 13.559 9.501 22.886 23.06 22.886zm-.087-9.586c-7.513 0-12.609-5.355-12.609-12.868 0-7.514 5.096-12.869 12.609-12.869 7.514 0 12.523 5.355 12.523 12.869 0 7.513-5.009 12.868-12.523 12.868z" fill="#fff"/><defs><linearGradient id="paint0_linear" x1="43.77" y1="98.175" x2="18.192" y2="19.347" gradientUnits="userSpaceOnUse"><stop stop-color="#E98ADA"/><stop offset="1" stop-color="#7E4DBD"/></linearGradient><linearGradient id="paint1_linear" x1="61.704" y1="61.223" x2="61.704" y2="98.349" gradientUnits="userSpaceOnUse"><stop stop-color="#719DED"/><stop offset="1" stop-color="#2545BE"/></linearGradient><linearGradient id="paint2_linear" x1="85.174" y1="17.058" x2="85.174" y2="61.223" gradientUnits="userSpaceOnUse"><stop stop-color="#93EBFF"/><stop offset="1" stop-color="#197DDB"/></linearGradient><linearGradient id="paint3_linear" x1="70.398" y1="0" x2="89.884" y2="34.697" gradientUnits="userSpaceOnUse"><stop stop-color="#F969D3"/><stop offset="1" stop-color="#4F51C0"/></linearGradient><linearGradient id="paint4_linear" x1="42.631" y1="103.868" x2="-16.624" y2="35.712" gradientUnits="userSpaceOnUse"><stop stop-color="#E98ADA"/><stop offset="1" stop-color="#7E4DBD"/></linearGradient></defs></svg>

Before

Width:  |  Height:  |  Size: 2.7 KiB

View file

@ -16,6 +16,8 @@ abstract class BuyProvider {
String get providerDescription;
String get providerSellDescription;
String get lightIcon;
String get darkIcon;

View file

@ -28,6 +28,9 @@ class DFXBuyProvider extends BuyProvider {
@override
String get providerDescription => S.current.dfx_option_description;
@override
String get providerSellDescription => providerDescription;
@override
String get lightIcon => 'assets/images/dfx_light.png';

View file

@ -1,63 +1,80 @@
import 'dart:convert';
import 'package:cake_wallet/.secrets.g.dart' as secrets;
import 'package:cake_wallet/buy/buy_provider.dart';
import 'package:cake_wallet/routes.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: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';
import 'package:http/http.dart' as http;
class MeldProvider extends BuyProvider {
MeldProvider({
required SettingsStore settingsStore,
required WalletBase wallet,
bool isTestEnvironment = false,
}) : baseSellUrl = isTestEnvironment ? _baseSellTestUrl : _baseSellProductUrl,
baseBuyUrl = isTestEnvironment ? _baseBuyTestUrl : _baseBuyProductUrl,
}) : baseSellUrl = isTestEnvironment ? _baseTestUrl : _baseProductUrl,
baseBuyUrl = isTestEnvironment ? _baseTestUrl : _baseProductUrl,
this._settingsStore = settingsStore,
super(wallet: wallet, isTestEnvironment: isTestEnvironment);
final SettingsStore _settingsStore;
static const _baseSellTestUrl = 'api-sb.meld.io';
static const _baseSellProductUrl = 'api.meld.io';
static const _baseBuyTestUrl = 'api-sb.meld.io';
static const _baseBuyProductUrl = 'api.meld.io';
static const _baseTestUrl = 'sb.fluidmoney.xyz';
static const _baseProductUrl = 'fluidmoney.xyz';
final String baseBuyUrl;
final String baseSellUrl;
@override
String get providerDescription => 'Meld provider description here';
String get providerDescription =>
'Buy crypto with many payment providers like Stripe and PayPal. Available in most countries. Spreads and feed vary.';
@override
String get providerSellDescription =>
'Sell crypto with many payment providers like Stripe and PayPal. Available in most countries. Spreads and feed vary.';
@override
String get title => 'Meld';
@override
String get lightIcon => 'assets/images/meld_light.svg';
String get lightIcon => 'assets/images/meld_dark.png';
@override
String get darkIcon => 'assets/images/meld_light.svg';
String get darkIcon => lightIcon;
String get currencyCode => walletTypeToCryptoCurrency(wallet.type).title.toLowerCase();
static String get _exchangeHelperApiKey => secrets.exchangeHelperApiKey;
static String convertTheme(ThemeBase theme) {
switch (theme.type) {
case ThemeType.bright:
case ThemeType.light:
return 'lightMode';
case ThemeType.dark:
return 'darkMode';
}
}
Future<Uri> requestSellUrl({
required CryptoCurrency currency,
required String refundWalletAddress,
required String walletAddress,
required SettingsStore settingsStore,
String? amount,
}) async {
throw UnimplementedError();
}
final params = {
"publicKey": secrets.meldApiKey,
"theme": convertTheme(settingsStore.currentTheme),
"sourceCurrencyCode": currencyCode.toUpperCase(),
"destinationCurrencyCode": settingsStore.fiatCurrency.raw,
"sourceAmount": amount ?? '100',
"walletAddress": walletAddress,
};
// BUY:
static const _buyWidgetSuffix = "/crypto/session/widget";
final uri = Uri.https(baseBuyUrl, '', params);
return uri;
}
Future<Uri> requestBuyUrl({
required CryptoCurrency currency,
@ -65,34 +82,17 @@ class MeldProvider extends BuyProvider {
required String walletAddress,
String? amount,
}) async {
try {
final headers = {
'Meld-Version': '2023-12-19',
'Content-Type': 'application/json',
'Authorization': 'BASIC ${secrets.meldApiKey}',
};
final body = {
"sessionData": {
"walletAddress": walletAddress,
"countryCode": _normalizeCountryCode(settingsStore.fiatCurrency.countryCode),
"sourceCurrencyCode": settingsStore.fiatCurrency.raw,
"sourceAmount": amount ?? '60',
"destinationCurrencyCode": currencyCode.toUpperCase(),
"serviceProvider": "STRIPE"
},
"sessionType": "BUY",
"externalCustomerId": "testcustomer",
};
final response = await http.post(
Uri.https(baseBuyUrl, _buyWidgetSuffix),
headers: headers,
body: json.encode(body),
);
return Uri.parse(json.decode(response.body)["widgetUrl"] as String);
} catch (e) {
print(e);
rethrow;
}
final params = {
"publicKey": secrets.meldApiKey,
"theme": convertTheme(settingsStore.currentTheme),
"destinationCurrencyCode": currencyCode.toUpperCase(),
"sourceCurrencyCode": settingsStore.fiatCurrency.raw,
"sourceAmount": amount ?? '100',
"walletAddress": walletAddress,
};
final uri = Uri.https(baseBuyUrl, '', params);
return uri;
}
@override
@ -107,7 +107,7 @@ class MeldProvider extends BuyProvider {
} else {
uri = await requestSellUrl(
currency: wallet.currency,
refundWalletAddress: wallet.walletAddresses.address,
walletAddress: wallet.walletAddresses.address,
settingsStore: _settingsStore,
);
}
@ -122,14 +122,4 @@ class MeldProvider extends BuyProvider {
throw Exception('Could not launch URL');
}
}
// normalize country codes to ISO-3166:
String _normalizeCountryCode(String countryCode) {
countryCode = countryCode.toLowerCase();
switch (countryCode) {
case "usa":
default:
return "US";
}
}
}
}

View file

@ -45,6 +45,9 @@ class MoonPayProvider extends BuyProvider {
String get providerDescription =>
'MoonPay offers a fast and simple way to buy and sell cryptocurrencies';
@override
String get providerSellDescription => providerDescription;
@override
String get title => 'MoonPay';

View file

@ -25,6 +25,9 @@ class OnRamperBuyProvider extends BuyProvider {
@override
String get providerDescription => S.current.onramper_option_description;
@override
String get providerSellDescription => providerDescription;
@override
String get lightIcon => 'assets/images/onramper_light.png';
@ -62,10 +65,9 @@ class OnRamperBuyProvider extends BuyProvider {
primaryColor = getColorStr(Theme.of(context).primaryColor);
secondaryColor = getColorStr(Theme.of(context).colorScheme.background);
primaryTextColor =
getColorStr(Theme.of(context).extension<CakeTextTheme>()!.titleColor);
secondaryTextColor = getColorStr(
Theme.of(context).extension<CakeTextTheme>()!.secondaryTextColor);
primaryTextColor = getColorStr(Theme.of(context).extension<CakeTextTheme>()!.titleColor);
secondaryTextColor =
getColorStr(Theme.of(context).extension<CakeTextTheme>()!.secondaryTextColor);
containerColor = getColorStr(Theme.of(context).colorScheme.background);
cardColor = getColorStr(Theme.of(context).cardColor);
@ -73,8 +75,7 @@ class OnRamperBuyProvider extends BuyProvider {
cardColor = getColorStr(Colors.white);
}
final networkName =
wallet.currency.fullName?.toUpperCase().replaceAll(" ", "");
final networkName = wallet.currency.fullName?.toUpperCase().replaceAll(" ", "");
return Uri.https(_baseUrl, '', <String, dynamic>{
'apiKey': _apiKey,
@ -95,8 +96,7 @@ class OnRamperBuyProvider extends BuyProvider {
Future<void> launchProvider(BuildContext context, bool? isBuyAction) async {
final uri = requestOnramperUrl(context, isBuyAction);
if (DeviceInfo.instance.isMobile) {
Navigator.of(context)
.pushNamed(Routes.webViewPage, arguments: [title, uri]);
Navigator.of(context).pushNamed(Routes.webViewPage, arguments: [title, uri]);
} else {
await launchUrl(uri);
}

View file

@ -24,6 +24,9 @@ class RobinhoodBuyProvider extends BuyProvider {
@override
String get providerDescription => S.current.robinhood_option_description;
@override
String get providerSellDescription => providerDescription;
@override
String get lightIcon => 'assets/images/robinhood_light.png';

View file

@ -36,6 +36,9 @@ class WyreBuyProvider extends BuyProvider {
@override
String get providerDescription => '';
@override
String get providerSellDescription => providerDescription;
@override
String get lightIcon => 'assets/images/robinhood_light.png';

View file

@ -45,7 +45,7 @@ class BuySellOptionsPage extends BasePage {
child: OptionTile(
image: icon,
title: provider.toString(),
description: provider.providerDescription,
description: isBuyAction ? provider.providerDescription : provider.providerSellDescription,
onPressed: () => provider.launchProvider(context, isBuyAction),
),
);