mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
start adding meld
This commit is contained in:
parent
62ef545fce
commit
a5fc98eca8
5 changed files with 184 additions and 1 deletions
1
.github/workflows/pr_test_build.yml
vendored
1
.github/workflows/pr_test_build.yml
vendored
|
@ -148,6 +148,7 @@ jobs:
|
|||
echo "const moralisApiKey = '${{ secrets.MORALIS_API_KEY }}';" >> lib/.secrets.g.dart
|
||||
echo "const polygonScanApiKey = '${{ secrets.POLYGON_SCAN_API_KEY }}';" >> cw_evm/lib/.secrets.g.dart
|
||||
echo "const ankrApiKey = '${{ secrets.ANKR_API_KEY }}';" >> cw_solana/lib/.secrets.g.dart
|
||||
echo "const meldApiKey = '${{ secrets.MELD_API_KEY }}';" >> lib/.secrets.g.dart
|
||||
|
||||
- name: Rename app
|
||||
run: |
|
||||
|
|
1
assets/images/meld_light.svg
Normal file
1
assets/images/meld_light.svg
Normal file
|
@ -0,0 +1 @@
|
|||
<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>
|
After Width: | Height: | Size: 2.7 KiB |
160
lib/buy/meld/meld_provider.dart
Normal file
160
lib/buy/meld/meld_provider.dart
Normal file
|
@ -0,0 +1,160 @@
|
|||
|
||||
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||
import 'package:cake_wallet/buy/buy_provider.dart';
|
||||
import 'package:cake_wallet/palette.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';
|
||||
|
||||
class MeldProvider extends BuyProvider {
|
||||
MeldProvider({
|
||||
required SettingsStore settingsStore,
|
||||
required WalletBase wallet,
|
||||
bool isTestEnvironment = false,
|
||||
}) : baseSellUrl = isTestEnvironment ? _baseSellTestUrl : _baseSellProductUrl,
|
||||
baseBuyUrl = isTestEnvironment ? _baseBuyTestUrl : _baseBuyProductUrl,
|
||||
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 _cIdBaseUrl = 'exchange-helper.cakewallet.com';
|
||||
|
||||
final String baseBuyUrl;
|
||||
final String baseSellUrl;
|
||||
|
||||
@override
|
||||
String get providerDescription => 'Meld provider description here';
|
||||
|
||||
@override
|
||||
String get title => 'Meld';
|
||||
|
||||
@override
|
||||
String get lightIcon => 'assets/images/meld_light.svg';
|
||||
|
||||
@override
|
||||
String get darkIcon => 'assets/images/moonpay_dark.png';
|
||||
|
||||
static String themeToMoonPayTheme(ThemeBase theme) {
|
||||
switch (theme.type) {
|
||||
case ThemeType.bright:
|
||||
case ThemeType.light:
|
||||
return 'light';
|
||||
case ThemeType.dark:
|
||||
return 'dark';
|
||||
}
|
||||
}
|
||||
|
||||
static String get _apiKey => secrets.moonPayApiKey;
|
||||
|
||||
String get currencyCode => walletTypeToCryptoCurrency(wallet.type).title.toLowerCase();
|
||||
|
||||
|
||||
static String get _exchangeHelperApiKey => secrets.exchangeHelperApiKey;
|
||||
|
||||
Future<Uri> requestSellUrl({
|
||||
required CryptoCurrency currency,
|
||||
required String refundWalletAddress,
|
||||
required SettingsStore settingsStore,
|
||||
}) async {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
// BUY:
|
||||
static const _currenciesSuffix = '/v3/currencies';
|
||||
static const _quoteSuffix = '/buy_quote';
|
||||
static const _transactionsSuffix = '/v1/transactions';
|
||||
static const _ipAddressSuffix = '/v4/ip_address';
|
||||
|
||||
Future<Uri> requestBuyUrl({
|
||||
required CryptoCurrency currency,
|
||||
required SettingsStore settingsStore,
|
||||
required String walletAddress,
|
||||
String? amount,
|
||||
}) async {
|
||||
final params = {
|
||||
'theme': themeToMoonPayTheme(settingsStore.currentTheme),
|
||||
'language': settingsStore.languageCode,
|
||||
'colorCode': settingsStore.currentTheme.type == ThemeType.dark
|
||||
? '#${Palette.blueCraiola.value.toRadixString(16).substring(2, 8)}'
|
||||
: '#${Palette.moderateSlateBlue.value.toRadixString(16).substring(2, 8)}',
|
||||
'defaultCurrencyCode': _normalizeCurrency(currency),
|
||||
'baseCurrencyCode': _normalizeCurrency(currency),
|
||||
'baseCurrencyAmount': amount ?? '0',
|
||||
'currencyCode': currencyCode,
|
||||
'walletAddress': walletAddress,
|
||||
'lockAmount': 'true',
|
||||
'showAllCurrencies': 'false',
|
||||
'showWalletAddressForm': 'false',
|
||||
'enabledPaymentMethods':
|
||||
'credit_debit_card,apple_pay,google_pay,samsung_pay,sepa_bank_transfer,gbp_bank_transfer,gbp_open_banking_payment',
|
||||
};
|
||||
|
||||
if (_apiKey.isNotEmpty) {
|
||||
params['apiKey'] = _apiKey;
|
||||
}
|
||||
|
||||
final originalUri = Uri.https(
|
||||
baseBuyUrl,
|
||||
'',
|
||||
params,
|
||||
);
|
||||
|
||||
if (isTestEnvironment) {
|
||||
return originalUri;
|
||||
}
|
||||
|
||||
return originalUri;
|
||||
// final signature = await getMoonpaySignature('?${originalUri.query}');
|
||||
// final query = Map<String, dynamic>.from(originalUri.queryParameters);
|
||||
// query['signature'] = signature;
|
||||
// final signedUri = originalUri.replace(queryParameters: query);
|
||||
// return signedUri;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> launchProvider(BuildContext context, bool? isBuyAction) async {
|
||||
late final Uri uri;
|
||||
if (isBuyAction ?? true) {
|
||||
uri = await requestBuyUrl(
|
||||
currency: wallet.currency,
|
||||
walletAddress: wallet.walletAddresses.address,
|
||||
settingsStore: _settingsStore,
|
||||
);
|
||||
} else {
|
||||
uri = await requestSellUrl(
|
||||
currency: wallet.currency,
|
||||
refundWalletAddress: wallet.walletAddresses.address,
|
||||
settingsStore: _settingsStore,
|
||||
);
|
||||
}
|
||||
|
||||
if (await canLaunchUrl(uri)) {
|
||||
if (DeviceInfo.instance.isMobile) {
|
||||
Navigator.of(context).pushNamed(Routes.webViewPage, arguments: ['Meld', uri]);
|
||||
} else {
|
||||
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
}
|
||||
} else {
|
||||
throw Exception('Could not launch URL');
|
||||
}
|
||||
}
|
||||
|
||||
String _normalizeCurrency(CryptoCurrency currency) {
|
||||
if (currency == CryptoCurrency.maticpoly) {
|
||||
return "MATIC_POLYGON";
|
||||
}
|
||||
|
||||
return currency.toString().toLowerCase();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:cake_wallet/anonpay/anonpay_api.dart';
|
||||
import 'package:cake_wallet/anonpay/anonpay_info_base.dart';
|
||||
import 'package:cake_wallet/anonpay/anonpay_invoice_info.dart';
|
||||
import 'package:cake_wallet/buy/meld/meld_provider.dart';
|
||||
import 'package:cake_wallet/buy/moonpay/moonpay_provider.dart';
|
||||
import 'package:cake_wallet/buy/onramper/onramper_buy_provider.dart';
|
||||
import 'package:cake_wallet/bitcoin_cash/bitcoin_cash.dart';
|
||||
|
@ -813,6 +814,12 @@ Future<void> setup({
|
|||
isTestEnvironment: kDebugMode,
|
||||
));
|
||||
|
||||
getIt.registerFactory<MeldProvider>(() => MeldProvider(
|
||||
settingsStore: getIt.get<AppStore>().settingsStore,
|
||||
wallet: getIt.get<AppStore>().wallet!,
|
||||
isTestEnvironment: kDebugMode,
|
||||
));
|
||||
|
||||
getIt.registerFactory<OnRamperBuyProvider>(() => OnRamperBuyProvider(
|
||||
getIt.get<AppStore>().settingsStore,
|
||||
wallet: getIt.get<AppStore>().wallet!,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:cake_wallet/buy/buy_provider.dart';
|
||||
import 'package:cake_wallet/buy/dfx/dfx_buy_provider.dart';
|
||||
import 'package:cake_wallet/buy/meld/meld_provider.dart';
|
||||
import 'package:cake_wallet/buy/moonpay/moonpay_provider.dart';
|
||||
import 'package:cake_wallet/buy/onramper/onramper_buy_provider.dart';
|
||||
import 'package:cake_wallet/buy/robinhood/robinhood_buy_provider.dart';
|
||||
|
@ -12,6 +13,7 @@ enum ProviderType {
|
|||
dfx,
|
||||
onramper,
|
||||
moonpay,
|
||||
meld,
|
||||
}
|
||||
|
||||
extension ProviderTypeName on ProviderType {
|
||||
|
@ -27,6 +29,8 @@ extension ProviderTypeName on ProviderType {
|
|||
return 'Onramper';
|
||||
case ProviderType.moonpay:
|
||||
return 'MoonPay';
|
||||
case ProviderType.meld:
|
||||
return 'Meld';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +46,8 @@ extension ProviderTypeName on ProviderType {
|
|||
return 'onramper_provider';
|
||||
case ProviderType.moonpay:
|
||||
return 'moonpay_provider';
|
||||
case ProviderType.meld:
|
||||
return 'meld_provider';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,10 +69,16 @@ class ProvidersHelper {
|
|||
ProviderType.dfx,
|
||||
ProviderType.robinhood,
|
||||
ProviderType.moonpay,
|
||||
ProviderType.meld,
|
||||
];
|
||||
case WalletType.litecoin:
|
||||
case WalletType.bitcoinCash:
|
||||
return [ProviderType.askEachTime, ProviderType.onramper, ProviderType.robinhood, ProviderType.moonpay];
|
||||
return [
|
||||
ProviderType.askEachTime,
|
||||
ProviderType.onramper,
|
||||
ProviderType.robinhood,
|
||||
ProviderType.moonpay
|
||||
];
|
||||
case WalletType.solana:
|
||||
return [ProviderType.askEachTime, ProviderType.onramper, ProviderType.robinhood];
|
||||
case WalletType.none:
|
||||
|
@ -115,6 +127,8 @@ class ProvidersHelper {
|
|||
return getIt.get<OnRamperBuyProvider>();
|
||||
case ProviderType.moonpay:
|
||||
return getIt.get<MoonPayProvider>();
|
||||
case ProviderType.meld:
|
||||
return getIt.get<MeldProvider>();
|
||||
case ProviderType.askEachTime:
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue