mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-03-12 09:32:33 +00:00
CAKE-279 | integrated Wyre to the app; added buy button to dashboard page for btc wallet; added buyCryptoCurrency() method to dashboard_view_model.dart
This commit is contained in:
parent
fd2cf98e51
commit
313f829689
3 changed files with 56 additions and 8 deletions
|
@ -1,3 +1,4 @@
|
|||
import 'package:cake_wallet/entities/wallet_type.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/routes.dart';
|
||||
import 'package:cake_wallet/themes/theme_base.dart';
|
||||
|
@ -12,6 +13,7 @@ import 'package:cake_wallet/src/screens/dashboard/widgets/address_page.dart';
|
|||
import 'package:cake_wallet/src/screens/dashboard/widgets/transactions_page.dart';
|
||||
import 'package:cake_wallet/src/screens/dashboard/widgets/sync_indicator.dart';
|
||||
import 'package:cake_wallet/view_model/wallet_address_list/wallet_address_list_view_model.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
||||
|
||||
class DashboardPage extends BasePage {
|
||||
|
@ -81,7 +83,7 @@ class DashboardPage extends BasePage {
|
|||
final exchangeImage = Image.asset('assets/images/transfer.png',
|
||||
height: 24.27, width: 22.25,
|
||||
color: Theme.of(context).accentTextTheme.display3.backgroundColor);
|
||||
final receiveImage = Image.asset('assets/images/download.png',
|
||||
final buyImage = Image.asset('assets/images/coins.png',
|
||||
height: 22.24, width: 24,
|
||||
color: Theme.of(context).accentTextTheme.display3.backgroundColor);
|
||||
_setEffects();
|
||||
|
@ -111,7 +113,7 @@ class DashboardPage extends BasePage {
|
|||
)),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 45, right: 45, bottom: 24),
|
||||
child: Row(
|
||||
child: Observer(builder: (_) => Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
ActionButton(
|
||||
|
@ -122,8 +124,12 @@ class DashboardPage extends BasePage {
|
|||
image: exchangeImage,
|
||||
title: S.of(context).exchange,
|
||||
route: Routes.exchange),
|
||||
if (walletViewModel.type == WalletType.bitcoin) ActionButton(
|
||||
image: buyImage,
|
||||
title: S.of(context).buy,
|
||||
onClick: () => walletViewModel.buyCryptoCurrency()),
|
||||
],
|
||||
),
|
||||
)),
|
||||
)
|
||||
],
|
||||
));
|
||||
|
|
|
@ -3,14 +3,16 @@ import 'package:flutter/material.dart';
|
|||
class ActionButton extends StatelessWidget {
|
||||
ActionButton(
|
||||
{@required this.image,
|
||||
@required this.title,
|
||||
@required this.route,
|
||||
this.alignment = Alignment.center});
|
||||
@required this.title,
|
||||
this.route,
|
||||
this.onClick,
|
||||
this.alignment = Alignment.center});
|
||||
|
||||
final Image image;
|
||||
final String title;
|
||||
final String route;
|
||||
final Alignment alignment;
|
||||
final void Function() onClick;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -23,8 +25,10 @@ class ActionButton extends StatelessWidget {
|
|||
children: <Widget>[
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (route.isNotEmpty) {
|
||||
if (route?.isNotEmpty ?? false) {
|
||||
Navigator.of(context, rootNavigator: true).pushNamed(route);
|
||||
} else {
|
||||
onClick?.call();
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
|
@ -48,4 +52,4 @@ class ActionButton extends StatelessWidget {
|
|||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,6 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_transaction_info.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cake_wallet/entities/balance.dart';
|
||||
|
@ -20,6 +23,8 @@ import 'package:cake_wallet/view_model/dashboard/trade_list_item.dart';
|
|||
import 'package:cake_wallet/view_model/dashboard/transaction_list_item.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/action_list_item.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/action_list_display_mode.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cake_wallet/core/wallet_base.dart';
|
||||
import 'package:cake_wallet/entities/sync_status.dart';
|
||||
|
@ -30,6 +35,9 @@ import 'package:cake_wallet/store/dashboard/trades_store.dart';
|
|||
import 'package:cake_wallet/store/dashboard/trade_filter_store.dart';
|
||||
import 'package:cake_wallet/store/dashboard/transaction_filter_store.dart';
|
||||
import 'package:cake_wallet/view_model/dashboard/formatted_item_list.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||
import 'package:convert/convert.dart';
|
||||
|
||||
part 'dashboard_view_model.g.dart';
|
||||
|
||||
|
@ -279,4 +287,34 @@ abstract class DashboardViewModelBase with Store {
|
|||
balanceViewModel: balanceViewModel,
|
||||
settingsStore: appStore.settingsStore)));
|
||||
}
|
||||
|
||||
void buyCryptoCurrency() async {
|
||||
final timestamp = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
final url = 'https://api.testwyre.com/v3/orders/reserve' + '?timestamp=' +
|
||||
timestamp;
|
||||
final apiKey = secrets.wyre_api_key;
|
||||
final secretKey = secrets.wyre_secret_key;
|
||||
final accountId = secrets.wyre_account_id;
|
||||
final body = {
|
||||
'destCurrency' : walletTypeToCryptoCurrency(type).title,
|
||||
'dest' : walletTypeToString(type).toLowerCase() + ':' + address,
|
||||
'referrerAccountId' : accountId,
|
||||
'lockFields' : ['destCurrency', 'dest']
|
||||
};
|
||||
|
||||
final response = await post(url,
|
||||
headers: {
|
||||
'Authorization': 'Bearer $secretKey',
|
||||
'Content-Type': 'application/json',
|
||||
'cache-control': 'no-cache'
|
||||
},
|
||||
body: json.encode(body)
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||
final urlFromResponse = responseJSON['url'] as String;
|
||||
if (await canLaunch(urlFromResponse)) await launch(urlFromResponse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue