mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-10 21:04:53 +00:00
Enable different currencies (#401)
This commit is contained in:
parent
3bd9301be1
commit
8321c9fbbe
5 changed files with 90 additions and 54 deletions
|
@ -8,6 +8,9 @@ class FiatCurrency extends EnumerableItem<String> with Serializable<String> {
|
||||||
|
|
||||||
static List<FiatCurrency> get all => _all.values.toList();
|
static List<FiatCurrency> get all => _all.values.toList();
|
||||||
|
|
||||||
|
static List<FiatCurrency> get currenciesAvailableToBuyWith =>
|
||||||
|
[aud, brl, cad, chf, czk, eur, dkk, gbp, hkd, ils, jpy, krw, mxn, myr, nok, nzd, pln, sek, sgd, thb, usd, zar];
|
||||||
|
|
||||||
static const aud = FiatCurrency(symbol: 'AUD', countryCode: "aus", fullName: "Australian Dollar");
|
static const aud = FiatCurrency(symbol: 'AUD', countryCode: "aus", fullName: "Australian Dollar");
|
||||||
static const bgn = FiatCurrency(symbol: 'BGN', countryCode: "bgr", fullName: "Bulgarian Lev");
|
static const bgn = FiatCurrency(symbol: 'BGN', countryCode: "bgr", fullName: "Bulgarian Lev");
|
||||||
static const brl = FiatCurrency(symbol: 'BRL', countryCode: "bra", fullName: "Brazilian Real");
|
static const brl = FiatCurrency(symbol: 'BRL', countryCode: "bra", fullName: "Brazilian Real");
|
||||||
|
|
|
@ -2,6 +2,8 @@ import 'dart:ui';
|
||||||
import 'package:cake_wallet/buy/buy_amount.dart';
|
import 'package:cake_wallet/buy/buy_amount.dart';
|
||||||
import 'package:cake_wallet/buy/buy_provider.dart';
|
import 'package:cake_wallet/buy/buy_provider.dart';
|
||||||
import 'package:cake_wallet/buy/moonpay/moonpay_buy_provider.dart';
|
import 'package:cake_wallet/buy/moonpay/moonpay_buy_provider.dart';
|
||||||
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||||
|
import 'package:cake_wallet/src/widgets/picker.dart';
|
||||||
import 'package:cw_core/wallet_type.dart';
|
import 'package:cw_core/wallet_type.dart';
|
||||||
import 'package:cake_wallet/src/screens/buy/widgets/buy_list_item.dart';
|
import 'package:cake_wallet/src/screens/buy/widgets/buy_list_item.dart';
|
||||||
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
||||||
|
@ -27,7 +29,6 @@ class PreOrderPage extends BasePage {
|
||||||
PreOrderPage({@required this.buyViewModel})
|
PreOrderPage({@required this.buyViewModel})
|
||||||
: _amountFocus = FocusNode(),
|
: _amountFocus = FocusNode(),
|
||||||
_amountController = TextEditingController() {
|
_amountController = TextEditingController() {
|
||||||
|
|
||||||
_amountController.addListener(() {
|
_amountController.addListener(() {
|
||||||
final amount = _amountController.text;
|
final amount = _amountController.text;
|
||||||
|
|
||||||
|
@ -110,52 +111,70 @@ class PreOrderPage extends BasePage {
|
||||||
.decorationColor,
|
.decorationColor,
|
||||||
], begin: Alignment.topLeft, end: Alignment.bottomRight),
|
], begin: Alignment.topLeft, end: Alignment.bottomRight),
|
||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.only(top: 100, bottom: 65),
|
padding: EdgeInsets.only(top: 100, bottom: 65),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 210,
|
width: 210,
|
||||||
child: BaseTextFormField(
|
child: BaseTextFormField(
|
||||||
focusNode: _amountFocus,
|
focusNode: _amountFocus,
|
||||||
controller: _amountController,
|
controller: _amountController,
|
||||||
keyboardType:
|
keyboardType: TextInputType.numberWithOptions(signed: false, decimal: true),
|
||||||
TextInputType.numberWithOptions(
|
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(_amountPattern))],
|
||||||
signed: false, decimal: true),
|
prefixIcon: GestureDetector(
|
||||||
inputFormatters: [
|
onTap: () {
|
||||||
FilteringTextInputFormatter
|
showPopUp<void>(
|
||||||
.allow(RegExp(_amountPattern))
|
context: context,
|
||||||
],
|
builder: (_) => Picker(
|
||||||
prefixIcon: Padding(
|
hintText: S.current.search_currency,
|
||||||
padding: EdgeInsets.only(top: 2),
|
items: FiatCurrency.currenciesAvailableToBuyWith,
|
||||||
child:
|
selectedAtIndex:
|
||||||
Text(buyViewModel.fiatCurrency.title + ': ',
|
FiatCurrency.currenciesAvailableToBuyWith.indexOf(buyViewModel.fiatCurrency),
|
||||||
style: TextStyle(
|
onItemSelected: (FiatCurrency selectedCurrency) {
|
||||||
fontSize: 36,
|
buyViewModel.buyAmountViewModel.fiatCurrency = selectedCurrency;
|
||||||
fontWeight: FontWeight.w600,
|
},
|
||||||
color: Colors.white,
|
images: FiatCurrency.currenciesAvailableToBuyWith
|
||||||
)),
|
.map((e) => Image.asset("assets/images/flags/${e.countryCode}.png"))
|
||||||
),
|
.toList(),
|
||||||
hintText: '0.00',
|
isGridView: true,
|
||||||
borderColor: Theme.of(context)
|
matchingCriteria: (FiatCurrency currency, String searchText) {
|
||||||
.primaryTextTheme
|
return currency.title.toLowerCase().contains(searchText) ||
|
||||||
.body2
|
currency.fullName.toLowerCase().contains(searchText);
|
||||||
.decorationColor,
|
},
|
||||||
borderWidth: 0.5,
|
),
|
||||||
textStyle: TextStyle(
|
);
|
||||||
|
},
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.only(top: 2),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.keyboard_arrow_down, color: Colors.white),
|
||||||
|
Text(
|
||||||
|
buyViewModel.fiatCurrency.title + ': ',
|
||||||
|
style: TextStyle(
|
||||||
fontSize: 36,
|
fontSize: 36,
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w600,
|
||||||
color: Colors.white),
|
color: Colors.white,
|
||||||
placeholderTextStyle: TextStyle(
|
),
|
||||||
color: Theme.of(context)
|
),
|
||||||
.primaryTextTheme
|
],
|
||||||
.headline
|
),
|
||||||
.decorationColor,
|
),
|
||||||
fontWeight: FontWeight.w500,
|
),
|
||||||
fontSize: 36),
|
hintText: '0.00',
|
||||||
)
|
borderColor: Theme.of(context).primaryTextTheme.body2.decorationColor,
|
||||||
)
|
borderWidth: 0.5,
|
||||||
)
|
textStyle: TextStyle(fontSize: 36, fontWeight: FontWeight.w500, color: Colors.white),
|
||||||
)
|
placeholderTextStyle: TextStyle(
|
||||||
|
color: Theme.of(context).primaryTextTheme.headline.decorationColor,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
fontSize: 36,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
if (buyViewModel.isShowProviderButtons) Padding(
|
if (buyViewModel.isShowProviderButtons) Padding(
|
||||||
padding: EdgeInsets.only(top: 38, bottom: 18),
|
padding: EdgeInsets.only(top: 38, bottom: 18),
|
||||||
|
@ -273,7 +292,7 @@ class PreOrderPage extends BasePage {
|
||||||
|
|
||||||
buyViewModel.isRunning = true;
|
buyViewModel.isRunning = true;
|
||||||
final url = await buyViewModel.fetchUrl();
|
final url = await buyViewModel.fetchUrl();
|
||||||
|
|
||||||
if (url.isNotEmpty) {
|
if (url.isNotEmpty) {
|
||||||
if (buyViewModel.selectedProvider is MoonPayBuyProvider) {
|
if (buyViewModel.selectedProvider is MoonPayBuyProvider) {
|
||||||
if (await canLaunch(url)) await launch(url);
|
if (await canLaunch(url)) await launch(url);
|
||||||
|
@ -287,4 +306,4 @@ class PreOrderPage extends BasePage {
|
||||||
buyViewModel.reset();
|
buyViewModel.reset();
|
||||||
buyViewModel.isRunning = false;
|
buyViewModel.isRunning = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'package:cake_wallet/di.dart';
|
||||||
|
import 'package:cake_wallet/store/settings_store.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||||
|
|
||||||
|
@ -6,12 +8,24 @@ part 'buy_amount_view_model.g.dart';
|
||||||
class BuyAmountViewModel = BuyAmountViewModelBase with _$BuyAmountViewModel;
|
class BuyAmountViewModel = BuyAmountViewModelBase with _$BuyAmountViewModel;
|
||||||
|
|
||||||
abstract class BuyAmountViewModelBase with Store {
|
abstract class BuyAmountViewModelBase with Store {
|
||||||
BuyAmountViewModelBase() : amount = '';
|
BuyAmountViewModelBase() {
|
||||||
|
amount = '';
|
||||||
|
|
||||||
|
int selectedIndex = FiatCurrency.currenciesAvailableToBuyWith
|
||||||
|
.indexOf(getIt.get<SettingsStore>().fiatCurrency);
|
||||||
|
|
||||||
|
if (selectedIndex == -1) {
|
||||||
|
selectedIndex = FiatCurrency.currenciesAvailableToBuyWith
|
||||||
|
.indexOf(FiatCurrency.usd);
|
||||||
|
}
|
||||||
|
fiatCurrency = FiatCurrency.currenciesAvailableToBuyWith[selectedIndex];
|
||||||
|
}
|
||||||
|
|
||||||
@observable
|
@observable
|
||||||
String amount;
|
String amount;
|
||||||
|
|
||||||
FiatCurrency get fiatCurrency => FiatCurrency.usd;
|
@observable
|
||||||
|
FiatCurrency fiatCurrency;
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
double get doubleAmount {
|
double get doubleAmount {
|
||||||
|
@ -25,4 +39,4 @@ abstract class BuyAmountViewModelBase with Store {
|
||||||
|
|
||||||
return _amount;
|
return _amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ abstract class BuyViewModelBase with Store {
|
||||||
|
|
||||||
double get doubleAmount => buyAmountViewModel.doubleAmount;
|
double get doubleAmount => buyAmountViewModel.doubleAmount;
|
||||||
|
|
||||||
|
@computed
|
||||||
FiatCurrency get fiatCurrency => buyAmountViewModel.fiatCurrency;
|
FiatCurrency get fiatCurrency => buyAmountViewModel.fiatCurrency;
|
||||||
|
|
||||||
CryptoCurrency get cryptoCurrency => walletTypeToCryptoCurrency(type);
|
CryptoCurrency get cryptoCurrency => walletTypeToCryptoCurrency(type);
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import 'package:cake_wallet/di.dart';
|
|
||||||
import 'package:cake_wallet/entities/language_service.dart';
|
import 'package:cake_wallet/entities/language_service.dart';
|
||||||
import 'package:cake_wallet/store/yat/yat_store.dart';
|
import 'package:cake_wallet/store/yat/yat_store.dart';
|
||||||
import 'package:cake_wallet/view_model/settings/choices_list_item.dart';
|
import 'package:cake_wallet/view_model/settings/choices_list_item.dart';
|
||||||
|
@ -172,9 +171,9 @@ abstract class SettingsViewModelBase with Store {
|
||||||
displayItem: (dynamic code) {
|
displayItem: (dynamic code) {
|
||||||
return LanguageService.list[code];
|
return LanguageService.list[code];
|
||||||
},
|
},
|
||||||
selectedItem: () => getIt.get<SettingsStore>().languageCode,
|
selectedItem: () => _settingsStore.languageCode,
|
||||||
onItemSelected: (String code) {
|
onItemSelected: (String code) {
|
||||||
getIt.get<SettingsStore>().languageCode = code;
|
_settingsStore.languageCode = code;
|
||||||
},
|
},
|
||||||
images: LanguageService.list.keys.map(
|
images: LanguageService.list.keys.map(
|
||||||
(e) => Image.asset("assets/images/flags/${LanguageService.localeCountryCode[e]}.png"))
|
(e) => Image.asset("assets/images/flags/${LanguageService.localeCountryCode[e]}.png"))
|
||||||
|
|
Loading…
Reference in a new issue