mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
slight improvement
This commit is contained in:
parent
cd69ce482b
commit
a7837d2014
9 changed files with 141 additions and 38 deletions
|
@ -15,7 +15,9 @@ import 'package:collection/collection.dart';
|
|||
enum OnRamperPartner {
|
||||
guardarian,
|
||||
paybis,
|
||||
utorg
|
||||
utorg,
|
||||
alchemypay,
|
||||
sardine
|
||||
}
|
||||
|
||||
extension Name on OnRamperPartner {
|
||||
|
@ -27,6 +29,10 @@ extension Name on OnRamperPartner {
|
|||
return 'Paybis';
|
||||
case OnRamperPartner.utorg:
|
||||
return 'Utorg';
|
||||
case OnRamperPartner.alchemypay:
|
||||
return 'Alchemy Pay';
|
||||
case OnRamperPartner.sardine:
|
||||
return 'Sardine';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,7 +144,7 @@ class OnRamperBuyProvider extends BuyProvider {
|
|||
final uri = requestOnramperUrl(context, isBuyAction);
|
||||
if (DeviceInfo.instance.isMobile) {
|
||||
Navigator.of(context)
|
||||
.pushNamed(Routes.webViewPage, arguments:[uri, providerType]);
|
||||
.pushNamed(Routes.webViewPage, arguments:[uri, providerType, isBuyAction]);
|
||||
} else {
|
||||
await launchUrl(uri);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ class Order extends HiveObject {
|
|||
final decoded = json.decode(jsonSource) as Map<String, dynamic>;
|
||||
final providerRaw = decoded['providerRaw'] as int?;
|
||||
final onramperPartnerRaw = decoded['onramperPartnerRaw'] as int?;
|
||||
final stateRaw = decoded['stateRaw'] as String?;
|
||||
|
||||
return Order(
|
||||
id: decoded['id'] as String,
|
||||
|
@ -50,7 +51,7 @@ class Order extends HiveObject {
|
|||
provider: providerRaw != null ? ProvidersHelper.deserialize(raw: providerRaw) : null,
|
||||
onramperPartner:
|
||||
onramperPartnerRaw != null ? OnRamperBuyProvider.fromRaw(onramperPartnerRaw) : null,
|
||||
state: TradeState.created,
|
||||
state: stateRaw != null ? TradeState.deserialize(raw: stateRaw) : null,
|
||||
from: decoded['from'] as String?,
|
||||
to: decoded['to'] as String?,
|
||||
);
|
||||
|
|
|
@ -814,7 +814,8 @@ Future<void> setup({
|
|||
getIt.registerFactoryParam<WebViewPage,List<dynamic>, void>((args, _) {
|
||||
final uri = args.first as Uri;
|
||||
final type = args.length > 1 ? args[1] as ProviderType? : null;
|
||||
return WebViewPage(uri, type, buyViewModel: getIt.get<BuyViewModel>());
|
||||
final isBuyAction = args.length > 2 ? args[2] as bool? : null;
|
||||
return WebViewPage(uri, type, isBuyAction, buyViewModel: getIt.get<BuyViewModel>());
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:cake_wallet/entities/provider_types.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/screens/base_page.dart';
|
||||
|
@ -11,12 +9,14 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
|||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class WebViewPage extends BasePage {
|
||||
WebViewPage(this._url, this._providerType, {required this.buyViewModel}) {
|
||||
WebViewPage(this._url, this._providerType, this.isBuyAction, {required this.buyViewModel}) {
|
||||
buyViewModel.selectedProviderType = _providerType;
|
||||
buyViewModel.isBuyAction = isBuyAction;
|
||||
}
|
||||
|
||||
final Uri _url;
|
||||
final ProviderType? _providerType;
|
||||
final bool? isBuyAction;
|
||||
final BuyViewModel buyViewModel;
|
||||
|
||||
@override
|
||||
|
|
|
@ -134,8 +134,8 @@ class TransactionsPage extends StatelessWidget {
|
|||
onTap: () => Navigator.of(context)
|
||||
.pushNamed(Routes.orderDetails, arguments: order),
|
||||
provider: ProvidersHelper.getProviderByType(order.provider!)!,
|
||||
from: order.from!,
|
||||
to: order.to!,
|
||||
from: order.from ?? '-',
|
||||
to: order.to ?? '-',
|
||||
createdAtFormattedDate:
|
||||
DateFormat('HH:mm').format(order.createdAt),
|
||||
formattedAmount: item.orderFormattedAmount,
|
||||
|
|
|
@ -53,7 +53,7 @@ class OrderRow extends StatelessWidget {
|
|||
color: Theme.of(context).extension<DashboardPageTheme>()!.textColor
|
||||
)),
|
||||
formattedAmount != null
|
||||
? Text(formattedAmount! + ' ' + to,
|
||||
? Text(formattedAmount! + ' ' + from,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
|
|
|
@ -30,28 +30,39 @@ abstract class BuyViewModelBase with Store {
|
|||
|
||||
ProviderType? selectedProviderType;
|
||||
|
||||
bool? isBuyAction;
|
||||
|
||||
WalletType get type => wallet.type;
|
||||
|
||||
@computed
|
||||
FiatCurrency get fiatCurrency => settingsStore.fiatCurrency;
|
||||
|
||||
CryptoCurrency get cryptoCurrency => walletTypeToCryptoCurrency(type);
|
||||
Future<void> saveOrder(String orderId,
|
||||
{int? onRamperPartnerRaw,
|
||||
String? fiatCurrency,
|
||||
String? cryptoCurrency,
|
||||
String? fiatAmount,
|
||||
String? cryptoAmount}) async {
|
||||
bool isBuyAction = this.isBuyAction ?? true;
|
||||
|
||||
final formattedCryptoCurrency =
|
||||
cryptoCurrency != null ? CryptoCurrency.fromString(cryptoCurrency) : null;
|
||||
|
||||
final orderData = {
|
||||
'id': orderId,
|
||||
'transferId': orderId,
|
||||
'createdAt': DateTime.now().toIso8601String(),
|
||||
'amount': isBuyAction ? fiatAmount ?? '' : cryptoAmount ?? '',
|
||||
'receiveAddress': '',
|
||||
'walletId': wallet.id,
|
||||
'providerRaw': ProvidersHelper.serialize(selectedProviderType ?? ProviderType.askEachTime),
|
||||
'onramperPartnerRaw': onRamperPartnerRaw,
|
||||
'from': isBuyAction ? fiatCurrency : formattedCryptoCurrency?.title,
|
||||
'to': isBuyAction ? formattedCryptoCurrency?.title : fiatCurrency,
|
||||
};
|
||||
|
||||
Future<void> saveOrder(String orderId, {int? onRamperPartnerRaw}) async {
|
||||
try {
|
||||
final String jsonSource = json.encode({
|
||||
'id': orderId,
|
||||
'transferId': orderId,
|
||||
'createdAt': DateTime.now().toIso8601String(),
|
||||
'amount': '0.0',
|
||||
'receiveAddress': 'address123',
|
||||
'walletId': wallet.id,
|
||||
'providerRaw': ProvidersHelper.serialize(selectedProviderType ?? ProviderType.askEachTime),
|
||||
'onramperPartnerRaw': onRamperPartnerRaw,
|
||||
'stateRaw': 'created',
|
||||
'from': fiatCurrency.title,
|
||||
'to': cryptoCurrency.title,
|
||||
}).toString();
|
||||
final String jsonSource = json.encode(orderData).toString();
|
||||
|
||||
final order = Order.fromJSON(jsonSource);
|
||||
|
||||
|
@ -65,18 +76,31 @@ abstract class BuyViewModelBase with Store {
|
|||
void processProviderUrl({required String urlStr}) async {
|
||||
if (selectedProviderType == null) return;
|
||||
|
||||
final orderId = extractInfoFromUrl(urlStr, selectedProviderType!);
|
||||
final orderId = extractInfoFromUrl(
|
||||
urlStr, selectedProviderType!, providerUrlOrderIdConfigs[selectedProviderType!]);
|
||||
final onRamperPartner = determineOnRamperPartner(urlStr);
|
||||
final onRamperPartnerRaw = onRamperPartner != null ? onRamperPartner.index : null;
|
||||
|
||||
if (orderId != null && orderId.isNotEmpty && orderId != this.orderId) {
|
||||
final fiatCurrency = extractInfoFromUrl(
|
||||
urlStr, selectedProviderType!, providerUrlFiatCurrencyConfigs[selectedProviderType!]);
|
||||
final cryptoCurrency = extractInfoFromUrl(
|
||||
urlStr, selectedProviderType!, providerUrlCryptoCurrencyConfigs[selectedProviderType!]);
|
||||
final fiatAmount = extractInfoFromUrl(
|
||||
urlStr, selectedProviderType!, providerUrlFiatAmountConfigs[selectedProviderType!]);
|
||||
final cryptoAmount = extractInfoFromUrl(
|
||||
urlStr, selectedProviderType!, providerUrlCryptoAmountConfigs[selectedProviderType!]);
|
||||
this.orderId = orderId;
|
||||
await saveOrder(orderId, onRamperPartnerRaw: onRamperPartnerRaw);
|
||||
await saveOrder(orderId,
|
||||
onRamperPartnerRaw: onRamperPartnerRaw,
|
||||
fiatCurrency: fiatCurrency,
|
||||
cryptoCurrency: cryptoCurrency,
|
||||
fiatAmount: fiatAmount,
|
||||
cryptoAmount: cryptoAmount);
|
||||
}
|
||||
}
|
||||
|
||||
String? extractInfoFromUrl(String url, ProviderType providerType) {
|
||||
final config = providerUrlConfigs[providerType];
|
||||
String? extractInfoFromUrl(String url, ProviderType providerType, ProviderUrlConfig? config) {
|
||||
if (config == null) return null;
|
||||
|
||||
for (var entry in config.parameterKeywords.entries) {
|
||||
|
@ -105,11 +129,15 @@ abstract class BuyViewModelBase with Store {
|
|||
return OnRamperPartner.paybis;
|
||||
} else if (url.contains('utpay')) {
|
||||
return OnRamperPartner.utorg;
|
||||
} else if (url.contains('alchemypay')) {
|
||||
return OnRamperPartner.alchemypay;
|
||||
} else if (url.contains('sardine')) {
|
||||
return OnRamperPartner.sardine;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
final Map<ProviderType, ProviderUrlConfig> providerUrlConfigs = {
|
||||
final Map<ProviderType, ProviderUrlConfig> providerUrlOrderIdConfigs = {
|
||||
ProviderType.onramper: ProviderUrlConfig(
|
||||
name: ProviderType.onramper.title,
|
||||
parameterKeywords: {
|
||||
|
@ -125,6 +153,74 @@ abstract class BuyViewModelBase with Store {
|
|||
'start': '/order/',
|
||||
'end': '/',
|
||||
},
|
||||
'alchemypay': {
|
||||
'start': 'merchantOrderNo=',
|
||||
'end': '&',
|
||||
},
|
||||
'sardine': {
|
||||
'start': 'client_token=',
|
||||
'end': null,
|
||||
},
|
||||
},
|
||||
),
|
||||
};
|
||||
|
||||
final Map<ProviderType, ProviderUrlConfig> providerUrlFiatCurrencyConfigs = {
|
||||
ProviderType.onramper: ProviderUrlConfig(
|
||||
name: ProviderType.onramper.title,
|
||||
parameterKeywords: {
|
||||
'alchemypay': {
|
||||
'start': 'fiat=',
|
||||
'end': '&',
|
||||
},
|
||||
'sardine': {
|
||||
'start': 'fixed_fiat_currency=',
|
||||
'end': '&',
|
||||
},
|
||||
},
|
||||
),
|
||||
};
|
||||
|
||||
final Map<ProviderType, ProviderUrlConfig> providerUrlCryptoCurrencyConfigs = {
|
||||
ProviderType.onramper: ProviderUrlConfig(
|
||||
name: ProviderType.onramper.title,
|
||||
parameterKeywords: {
|
||||
'alchemypay': {
|
||||
'start': 'crypto=',
|
||||
'end': '&',
|
||||
},
|
||||
'sardine': {
|
||||
'start': 'fixed_asset_type=',
|
||||
'end': '&',
|
||||
},
|
||||
},
|
||||
),
|
||||
};
|
||||
|
||||
final Map<ProviderType, ProviderUrlConfig> providerUrlFiatAmountConfigs = {
|
||||
ProviderType.onramper: ProviderUrlConfig(
|
||||
name: ProviderType.onramper.title,
|
||||
parameterKeywords: {
|
||||
'alchemypay': {
|
||||
'start': 'fiatAmount=',
|
||||
'end': '&',
|
||||
},
|
||||
'sardine': {
|
||||
'start': 'fixed_fiat_amount=',
|
||||
'end': '&',
|
||||
},
|
||||
},
|
||||
),
|
||||
};
|
||||
|
||||
final Map<ProviderType, ProviderUrlConfig> providerUrlCryptoAmountConfigs = {
|
||||
ProviderType.onramper: ProviderUrlConfig(
|
||||
name: ProviderType.onramper.title,
|
||||
parameterKeywords: {
|
||||
'alchemypay': {
|
||||
'start': 'cryptoAmount=',
|
||||
'end': '&',
|
||||
},
|
||||
},
|
||||
),
|
||||
};
|
||||
|
|
|
@ -14,11 +14,9 @@ class OrderListItem extends ActionListItem {
|
|||
BalanceDisplayMode get displayMode => settingsStore.balanceDisplayMode;
|
||||
|
||||
String get orderFormattedAmount {
|
||||
return order.amount != null
|
||||
? displayMode == BalanceDisplayMode.hiddenBalance
|
||||
return displayMode == BalanceDisplayMode.hiddenBalance
|
||||
? '---'
|
||||
: order.amountFormatted()
|
||||
: order.amount;
|
||||
: order.amountFormatted();
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -67,11 +67,12 @@ abstract class OrderDetailsViewModelBase with Store {
|
|||
StandartListItem(
|
||||
title: 'Transfer ID',
|
||||
value: order.transferId),
|
||||
|
||||
|
||||
if(order.state != null)
|
||||
StandartListItem(
|
||||
title: S.current.trade_details_state,
|
||||
value: order.state != null
|
||||
? order.state.toString()
|
||||
: S.current.trade_details_fetching),
|
||||
value: order.state.toString())
|
||||
]);
|
||||
|
||||
items.add(
|
||||
|
@ -112,7 +113,7 @@ abstract class OrderDetailsViewModelBase with Store {
|
|||
items.add(
|
||||
StandartListItem(
|
||||
title: S.current.trade_details_pair,
|
||||
value: '${order.from} → ${order.to}')
|
||||
value: '${order.from ?? '-'} → ${order.to ?? '-'}')
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue