diff --git a/lib/di.dart b/lib/di.dart index 0ad5cf54d..0a7ad4d3e 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -2,6 +2,10 @@ import 'package:cake_wallet/entities/wake_lock.dart'; import 'package:cake_wallet/monero/monero.dart'; import 'package:cake_wallet/bitcoin/bitcoin.dart'; import 'package:cake_wallet/src/screens/loan/loan_account_page.dart'; +import 'package:cake_wallet/src/screens/loan/loan_detail_page.dart'; +import 'package:cake_wallet/view_model/loan/loan_account_view_model.dart'; +import 'package:cake_wallet/view_model/loan/loan_detail_view_model.dart'; +import 'package:cake_wallet/view_model/loan/loan_item.dart'; import 'package:cw_core/unspent_coins_info.dart'; import 'package:cake_wallet/core/backup_service.dart'; import 'package:cw_core/wallet_service.dart'; @@ -624,7 +628,21 @@ Future setup( getIt.registerFactory(() => WakeLock()); - getIt.registerFactory(() => LoanAccountPage()); + getIt.registerFactory<LoanAccountViewModel>( + () => LoanAccountViewModel(wallet: getIt.get<AppStore>().wallet)); + + getIt.registerFactory(() => + LoanAccountPage(loanAccountViewModel: getIt.get<LoanAccountViewModel>())); + + getIt.registerFactoryParam<LoanDetailViewModel, LoanItem, void>( + (LoanItem loanDetail, _) { + return LoanDetailViewModel(loanItem: loanDetail); + }); + + getIt.registerFactoryParam<LoanDetailPage, LoanItem, void>( + (LoanItem loanItem, _) => LoanDetailPage( + loanDetailViewModel: + getIt.get<LoanDetailViewModel>(param1: loanItem))); _isSetupFinished = true; } diff --git a/lib/router.dart b/lib/router.dart index 446b0ad4e..1fd3aee9e 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -1,11 +1,11 @@ import 'package:cake_wallet/entities/contact_record.dart'; import 'package:cake_wallet/buy/order.dart'; -import 'package:cake_wallet/entities/transaction_description.dart'; import 'package:cake_wallet/src/screens/backup/backup_page.dart'; import 'package:cake_wallet/src/screens/backup/edit_backup_password_page.dart'; import 'package:cake_wallet/src/screens/buy/buy_webview_page.dart'; import 'package:cake_wallet/src/screens/buy/pre_order_page.dart'; import 'package:cake_wallet/src/screens/loan/loan_account_page.dart'; +import 'package:cake_wallet/src/screens/loan/loan_detail_page.dart'; import 'package:cake_wallet/src/screens/order_details/order_details_page.dart'; import 'package:cake_wallet/src/screens/pin_code/pin_code_widget.dart'; import 'package:cake_wallet/src/screens/restore/restore_from_backup_page.dart'; @@ -14,10 +14,8 @@ import 'package:cake_wallet/src/screens/seed/pre_seed_page.dart'; import 'package:cake_wallet/src/screens/support/support_page.dart'; import 'package:cake_wallet/src/screens/unspent_coins/unspent_coins_details_page.dart'; import 'package:cake_wallet/src/screens/unspent_coins/unspent_coins_list_page.dart'; -import 'package:cake_wallet/store/settings_store.dart'; -import 'package:cake_wallet/view_model/buy/buy_view_model.dart'; +import 'package:cake_wallet/view_model/loan/loan_item.dart'; import 'package:cake_wallet/view_model/monero_account_list/account_list_item.dart'; -import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_item.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/routes.dart'; @@ -27,7 +25,6 @@ import 'package:cake_wallet/utils/language_list.dart'; import 'package:cake_wallet/view_model/wallet_new_vm.dart'; import 'package:cake_wallet/view_model/wallet_restoration_from_seed_vm.dart'; import 'package:cake_wallet/view_model/wallet_restoration_from_keys_vm.dart'; -import 'package:cake_wallet/entities/contact.dart'; import 'package:cake_wallet/exchange/trade.dart'; import 'package:cw_core/transaction_info.dart'; import 'package:cw_core/wallet_type.dart'; @@ -67,7 +64,6 @@ import 'package:cake_wallet/src/screens/exchange/exchange_template_page.dart'; import 'package:cake_wallet/src/screens/exchange_trade/exchange_confirm_page.dart'; import 'package:cake_wallet/src/screens/exchange_trade/exchange_trade_page.dart'; import 'package:flutter/services.dart'; -import 'package:hive/hive.dart'; import 'package:cake_wallet/wallet_type_utils.dart'; RouteSettings currentRouteSettings; @@ -401,6 +397,10 @@ Route<dynamic> createRoute(RouteSettings settings) { return CupertinoPageRoute<void>( fullscreenDialog: true, builder: (_) => getIt.get<LoanAccountPage>()); + case Routes.loanDetails: + return MaterialPageRoute<void>( + builder: (_) => + getIt.get<LoanDetailPage>(param1: settings.arguments as LoanItem)); default: return MaterialPageRoute<void>( diff --git a/lib/routes.dart b/lib/routes.dart index f447d2d03..1b8e96d56 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -8,7 +8,8 @@ class Routes { static const restoreOptions = '/restore_options'; static const restoreOptionsFromWelcome = '/restore_options_from_welcome'; static const restoreWalletOptions = '/restore_seed_keys'; - static const restoreWalletOptionsFromWelcome = '/restore_wallet_options_from_welcome'; + static const restoreWalletOptionsFromWelcome = + '/restore_wallet_options_from_welcome'; static const restoreWalletFromSeed = '/restore_wallet_from_seed'; static const restoreWalletFromKeys = '/restore_wallet_from_keys'; static const dashboard = '/dashboard'; @@ -60,4 +61,5 @@ class Routes { static const moneroRestoreWalletFromWelcome = '/monero_restore_wallet'; static const moneroNewWalletFromWelcome = '/monero_new_wallet'; static const loanAccount = '/loan_account'; -} \ No newline at end of file + static const loanDetails = '/loan_details'; +} diff --git a/lib/src/screens/loan/loan_account_page.dart b/lib/src/screens/loan/loan_account_page.dart index 0d1cc5abb..7b4521f02 100644 --- a/lib/src/screens/loan/loan_account_page.dart +++ b/lib/src/screens/loan/loan_account_page.dart @@ -1,26 +1,37 @@ -import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/src/screens/base_page.dart'; -import 'package:cake_wallet/src/screens/dashboard/widgets/action_button.dart'; import 'package:cake_wallet/src/screens/dashboard/widgets/sync_indicator_icon.dart'; -import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; +import 'package:cake_wallet/src/screens/loan/widgets/loan_list_item.dart'; +import 'package:cake_wallet/src/screens/loan/widgets/loan_login_section.dart'; +import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; import 'package:cake_wallet/src/widgets/primary_button.dart'; import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart'; -import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/themes/theme_base.dart'; +import 'package:cake_wallet/view_model/loan/loan_account_view_model.dart'; import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; +import 'package:keyboard_actions/keyboard_actions.dart'; class LoanAccountPage extends BasePage { - LoanAccountPage({Key key}); + LoanAccountPage({@required this.loanAccountViewModel}) + : _emailFocus = FocusNode(), + _emailController = TextEditingController(), + _codeFocus = FocusNode(), + _codeController = TextEditingController(); + + final LoanAccountViewModel loanAccountViewModel; + + final FocusNode _emailFocus; + final TextEditingController _emailController; + + final FocusNode _codeFocus; + final TextEditingController _codeController; + @override String get title => 'Loan Account'; @override Color get titleColor => Colors.white; - @override - bool get resizeToAvoidBottomInset => false; - @override bool get extendBodyBehindAppBar => true; @@ -36,336 +47,139 @@ class LoanAccountPage extends BasePage { children: [ Padding( padding: const EdgeInsets.only(right: 20.0), - child: SyncIndicatorIcon(isSynced: false), + child: Observer( + builder: (_) => + SyncIndicatorIcon(isSynced: loanAccountViewModel.status), + ), ), super.middle(context), ], ); @override Widget body(BuildContext context) { - return ScrollableWithBottomSection( - contentPadding: EdgeInsets.zero, - content: Column( - children: [ - Container( - padding: EdgeInsets.symmetric(horizontal: 14), - decoration: BoxDecoration( - borderRadius: BorderRadius.only( - bottomLeft: Radius.circular(24), - bottomRight: Radius.circular(24)), - gradient: LinearGradient(colors: [ - Theme.of(context).primaryTextTheme.subhead.color, - Theme.of(context).primaryTextTheme.subhead.decorationColor, - ], begin: Alignment.topLeft, end: Alignment.bottomRight), + return KeyboardActions( + config: KeyboardActionsConfig( + keyboardActionsPlatform: KeyboardActionsPlatform.IOS, + keyboardBarColor: + Theme.of(context).accentTextTheme.body2.backgroundColor, + nextFocus: false, + actions: [ + KeyboardActionsItem( + focusNode: _emailFocus, + toolbarButtons: [(_) => KeyboardDoneButton()], ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox(height: 150), - SizedBox( - height: 40, - child: Row( - children: [ - Expanded( - child: BaseTextFormField( - textColor: Colors.white, - hintText: 'Email OR Phone Number', - placeholderTextStyle: - TextStyle(color: Colors.white54), - ), - ), - SizedBox( - width: 90, - child: PrimaryButton( - onPressed: () {}, - text: 'Get code', - color: Colors.white.withOpacity(0.2), - radius: 6, - textColor: Colors.white, - ), - ), - ], - ), - ), - SizedBox(height: 37), - SizedBox( - height: 40, - child: Row( - children: [ - Expanded( - child: BaseTextFormField( - textColor: Colors.white, - hintText: 'SMS / Email Code', - placeholderTextStyle: - TextStyle(color: Colors.white54), - ), - ), - SizedBox(width: 10), - SizedBox( - width: 70, - child: PrimaryButton( - onPressed: () {}, - text: 'Verify', - color: Colors.white.withOpacity(0.2), - radius: 6, - textColor: Colors.white), - ), - SizedBox(width: 10) - ], - ), - ), - SizedBox(height: 100), - ], + KeyboardActionsItem( + focusNode: _codeFocus, + toolbarButtons: [(_) => KeyboardDoneButton()], ), - ), - Column( + ]), + child: Container( + height: 0, + color: Theme.of(context).backgroundColor, + child: ScrollableWithBottomSection( + contentPadding: EdgeInsets.zero, + content: Column( children: [ - SizedBox(height: 40), - Theme( - data: Theme.of(context).copyWith( - dividerColor: Colors.transparent, - hoverColor: Colors.transparent, + Container( + padding: EdgeInsets.symmetric(horizontal: 14), + decoration: BoxDecoration( + borderRadius: BorderRadius.only( + bottomLeft: Radius.circular(24), + bottomRight: Radius.circular(24)), + gradient: LinearGradient(colors: [ + Theme.of(context).primaryTextTheme.subhead.color, + Theme.of(context).primaryTextTheme.subhead.decorationColor, + ], begin: Alignment.topLeft, end: Alignment.bottomRight), ), - child: ExpansionTile( - initiallyExpanded: true, - trailing: Icon( - Icons.keyboard_arrow_down, - color: textColor, - size: 30, - ), - childrenPadding: EdgeInsets.symmetric(horizontal: 20), - title: Text( - 'My Lending/Earning', - style: TextStyle( - fontWeight: FontWeight.w600, - color: textColor, - fontSize: 24, - ), - ), + child: Column( + mainAxisSize: MainAxisSize.min, children: [ - Align( - alignment: Alignment.bottomLeft, - child: Text( - 'Log in above to lend', - style: TextStyle( - fontWeight: FontWeight.w400, - color: textColor, - fontSize: 14, - ), - ), - ), + SizedBox(height: 130), + Observer(builder: (_) { + final isLoggedIn = loanAccountViewModel.isLoggedIn; + if (isLoggedIn) return SizedBox(width: double.infinity); + return LoanLoginSection( + emailController: _emailController, + emailFocus: _emailFocus, + codeFocus: _codeFocus, + codeController: _codeController, + ); + }) ], ), ), - SizedBox(height: 40), - Theme( - data: Theme.of(context).copyWith( - dividerColor: Colors.transparent, - hoverColor: Colors.transparent, - ), - child: ExpansionTile( - initiallyExpanded: true, - trailing: Icon( - Icons.keyboard_arrow_down, - color: textColor, - size: 30, + Column( + children: [ + SizedBox(height: 40), + LoanListItem( + textColor: textColor, + title: 'My Lending/Earning', + loginText: 'Log in above to lend', + loanAccountViewModel: loanAccountViewModel, + emptyListText: 'No open lendings/earnings yet', ), - childrenPadding: EdgeInsets.symmetric(horizontal: 20), - title: Text( - 'My Borrowing', - style: TextStyle( - fontWeight: FontWeight.w600, - color: textColor, - fontSize: 24, - ), + LoanListItem( + textColor: textColor, + title: 'My Borrowing', + loginText: 'Log in above to borrow with collateral', + emptyListText: 'No open loans yet', + loanAccountViewModel: loanAccountViewModel, ), - children: [ - Align( - alignment: Alignment.bottomLeft, - child: Text( - 'Log in above to borrow with collateral', - style: TextStyle( - fontWeight: FontWeight.w400, - color: textColor, - fontSize: 14, - ), - ), - ), - Table(), - ], - ), - ) + ], + ), ], ), - ], - ), - bottomSection: Column( - children: [ - Padding( - padding: EdgeInsets.only(bottom: 12), - child: PrimaryButton( - onPressed: () {}, - text: 'Lend and Earn Interest', - color: Theme.of(context).accentTextTheme.body2.color, - textColor: Colors.white, - ), - ), - SizedBox(height: 20), - RichText( - textAlign: TextAlign.center, - text: TextSpan( - text: 'By logging in, you agree to the ', - style: TextStyle(color: Color(0xff7A93BA), fontSize: 12), + bottomSection: Observer(builder: (_) { + return Column( children: [ - TextSpan( - text: 'Terms and Conditions', - style: TextStyle(decoration: TextDecoration.underline), - ), - TextSpan(text: ' and '), - TextSpan( - text: 'Privacy Policy of CoinRabbit', - style: TextStyle(decoration: TextDecoration.underline), - ) + if (loanAccountViewModel.isLoggedIn) ...[ + SizedBox(height: 20), + Padding( + padding: EdgeInsets.only(bottom: 12), + child: PrimaryButton( + onPressed: () {}, + text: 'Lend and Earn Interest', + color: Theme.of(context).accentTextTheme.body2.color, + textColor: Colors.white, + ), + ), + Padding( + padding: EdgeInsets.only(bottom: 12), + child: PrimaryButton( + onPressed: () {}, + text: ' Borrow with Collateral', + color: Theme.of(context).accentTextTheme.body2.color, + textColor: Colors.white, + ), + ), + SizedBox(height: 20), + ] else + RichText( + textAlign: TextAlign.center, + text: TextSpan( + text: 'By logging in, you agree to the ', + style: TextStyle(color: Color(0xff7A93BA), fontSize: 12), + children: [ + TextSpan( + text: 'Terms and Conditions', + style: + TextStyle(decoration: TextDecoration.underline), + ), + TextSpan(text: ' and '), + TextSpan( + text: 'Privacy Policy of CoinRabbit', + style: + TextStyle(decoration: TextDecoration.underline), + ) + ], + ), + ), + SizedBox(height: 10) ], - ), - ), - SizedBox(height: 10) - ], + ); + }), + ), ), ); } } - -class Table extends StatelessWidget { - const Table({Key key}) : super(key: key); - - Color get textColor => - getIt.get<SettingsStore>().currentTheme.type == ThemeType.dark - ? Colors.white - : Color(0xff393939); - @override - Widget build(BuildContext context) { - return Column( - children: [ - Padding( - padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10), - child: Row( - children: [ - Expanded( - child: Text( - 'ID', - style: TextStyle(color: textColor), - ), - ), - Expanded( - child: Text( - 'Amount', - style: TextStyle(color: textColor), - ), - ), - Expanded( - child: Text( - 'Status', - style: TextStyle(color: textColor), - ), - ), - SizedBox(width: 25), - ], - ), - ), - Container( - padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Color(0xffF1EDFF), - ), - child: Row( - children: [ - Expanded( - child: Text( - '5395821325', - style: TextStyle(color: textColor), - ), - ), - Expanded( - child: Text( - '10000 USDT', - style: TextStyle(color: textColor), - ), - ), - Expanded( - child: Text( - 'Awaiting deposit', - style: TextStyle(color: textColor), - ), - ), - Icon(Icons.chevron_right) - ], - ), - ), - SizedBox(height: 10), - Container( - padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Color(0xffF1EDFF), - ), - child: Row( - children: [ - Expanded( - child: Text( - '5395821325', - style: TextStyle(color: textColor), - ), - ), - Expanded( - child: Text( - '10000 USDT', - style: TextStyle(color: textColor), - ), - ), - Expanded( - child: Text( - 'Awaiting deposit', - style: TextStyle(color: textColor), - ), - ), - Icon(Icons.chevron_right) - ], - ), - ), - SizedBox(height: 10), - Container( - padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: Color(0xffF1EDFF), - ), - child: Row( - children: [ - Expanded( - child: Text( - '5395821325', - style: TextStyle(color: textColor), - ), - ), - Expanded( - child: Text( - '10000 USDT', - style: TextStyle(color: textColor), - ), - ), - Expanded( - child: Text( - 'Awaiting deposit', - style: TextStyle(color: textColor), - ), - ), - Icon(Icons.chevron_right) - ], - ), - ), - ], - ); - } -} diff --git a/lib/src/screens/loan/loan_detail_page.dart b/lib/src/screens/loan/loan_detail_page.dart new file mode 100644 index 000000000..924f6c079 --- /dev/null +++ b/lib/src/screens/loan/loan_detail_page.dart @@ -0,0 +1,14 @@ +import 'package:cake_wallet/src/screens/base_page.dart'; +import 'package:cake_wallet/view_model/loan/loan_detail_view_model.dart'; +import 'package:flutter/material.dart'; + +class LoanDetailPage extends BasePage { + LoanDetailPage({this.loanDetailViewModel}); + + final LoanDetailViewModel loanDetailViewModel; + + @override + Widget body(BuildContext context) { + return Container(); + } +} diff --git a/lib/src/screens/loan/widgets/loan_list_item.dart b/lib/src/screens/loan/widgets/loan_list_item.dart new file mode 100644 index 000000000..3bebb0b84 --- /dev/null +++ b/lib/src/screens/loan/widgets/loan_list_item.dart @@ -0,0 +1,69 @@ +import 'package:cake_wallet/src/screens/loan/widgets/loan_table.dart'; +import 'package:cake_wallet/view_model/loan/loan_account_view_model.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_mobx/flutter_mobx.dart'; + +class LoanListItem extends StatelessWidget { + const LoanListItem({ + Key key, + @required this.textColor, + @required this.title, + @required this.loginText, + @required this.loanAccountViewModel, + @required this.emptyListText, + }) : super(key: key); + + final Color textColor; + final String title; + final String loginText; + final String emptyListText; + final LoanAccountViewModel loanAccountViewModel; + + @override + Widget build(BuildContext context) { + return Theme( + data: Theme.of(context).copyWith( + dividerColor: Colors.transparent, + hoverColor: Colors.transparent, + ), + child: Observer(builder: (_) { + return ExpansionTile( + initiallyExpanded: true, + trailing: Icon( + Icons.keyboard_arrow_down, + color: textColor, + size: 30, + ), + childrenPadding: EdgeInsets.symmetric(horizontal: 20), + title: Text( + title, + style: TextStyle( + fontWeight: FontWeight.w600, + color: textColor, + fontSize: 24, + ), + ), + children: [ + if (!loanAccountViewModel.isLoggedIn) + Align( + alignment: Alignment.bottomLeft, + child: Text( + loginText, + style: TextStyle( + fontWeight: FontWeight.w400, + color: textColor, + fontSize: 14, + ), + ), + ) + else + LoanTable( + loanItems: loanAccountViewModel.items, + emptyListText: emptyListText, + ), + ], + ); + }), + ); + } +} diff --git a/lib/src/screens/loan/widgets/loan_login_section.dart b/lib/src/screens/loan/widgets/loan_login_section.dart new file mode 100644 index 000000000..17a8a031c --- /dev/null +++ b/lib/src/screens/loan/widgets/loan_login_section.dart @@ -0,0 +1,81 @@ +import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; +import 'package:cake_wallet/src/widgets/primary_button.dart'; +import 'package:flutter/material.dart'; + +class LoanLoginSection extends StatelessWidget { + const LoanLoginSection({ + @required this.emailFocus, + @required this.codeFocus, + @required this.emailController, + @required this.codeController, + }); + + final FocusNode emailFocus; + final TextEditingController emailController; + + final FocusNode codeFocus; + final TextEditingController codeController; + + @override + Widget build(BuildContext context) { + return Column( + children: [ + SizedBox( + height: 40, + child: Row( + children: [ + Expanded( + child: BaseTextFormField( + textColor: Colors.white, + hintText: 'Email OR Phone Number', + focusNode: emailFocus, + controller: emailController, + placeholderTextStyle: TextStyle(color: Colors.white54), + ), + ), + SizedBox( + width: 90, + child: PrimaryButton( + onPressed: () {}, + text: 'Get code', + color: Colors.white.withOpacity(0.2), + radius: 6, + textColor: Colors.white, + ), + ), + ], + ), + ), + SizedBox(height: 37), + SizedBox( + height: 40, + child: Row( + children: [ + Expanded( + child: BaseTextFormField( + textColor: Colors.white, + hintText: 'SMS / Email Code', + focusNode: codeFocus, + controller: codeController, + placeholderTextStyle: TextStyle(color: Colors.white54), + ), + ), + SizedBox(width: 10), + SizedBox( + width: 70, + child: PrimaryButton( + onPressed: () {}, + text: 'Verify', + color: Colors.white.withOpacity(0.2), + radius: 6, + textColor: Colors.white), + ), + SizedBox(width: 10) + ], + ), + ), + SizedBox(height: 100), + ], + ); + } +} diff --git a/lib/src/screens/loan/widgets/loan_table.dart b/lib/src/screens/loan/widgets/loan_table.dart new file mode 100644 index 000000000..38cbb264c --- /dev/null +++ b/lib/src/screens/loan/widgets/loan_table.dart @@ -0,0 +1,112 @@ +import 'package:cake_wallet/di.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/view_model/loan/loan_item.dart'; +import 'package:flutter/material.dart'; + +class LoanTable extends StatelessWidget { + LoanTable({ + @required this.loanItems, + @required this.emptyListText, + }); + final List<LoanItem> loanItems; + final String emptyListText; + + Color get textColor => + getIt.get<SettingsStore>().currentTheme.type == ThemeType.dark + ? Colors.white + : Color(0xff393939); + + @override + Widget build(BuildContext context) { + final items = loanItems; + if (items == null || items.isEmpty) + return Align( + alignment: Alignment.bottomLeft, + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 5), + child: Text( + emptyListText, + style: TextStyle( + fontWeight: FontWeight.w400, + color: textColor, + fontSize: 14, + ), + ), + ), + ); + return Column( + children: [ + Padding( + padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10), + child: Row( + children: [ + Expanded( + child: Text( + 'ID', + style: TextStyle(color: textColor), + ), + ), + Expanded( + child: Text( + 'Amount', + style: TextStyle(color: textColor), + ), + ), + Expanded( + child: Text( + 'Status', + style: TextStyle(color: textColor), + ), + ), + SizedBox(width: 25), + ], + ), + ), + Column( + children: [ + for (var i = 0; i < items.length; i++) ...[ + InkWell( + onTap: ()=>Navigator.of(context).pushNamed( + Routes.loanDetails, + arguments: items[i]), + child: Container( + padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Color(0xffF1EDFF), + ), + child: Row( + children: [ + Expanded( + child: Text( + '5395821325', + style: TextStyle(color: textColor), + ), + ), + Expanded( + child: Text( + '10000 USDT', + style: TextStyle(color: textColor), + ), + ), + Expanded( + child: Text( + 'Awaiting deposit', + style: TextStyle(color: textColor), + ), + ), + Icon(Icons.chevron_right) + ], + ), + ), + ), + SizedBox(height: 10), + ] + ], + ) + ], + ); + } +} diff --git a/lib/src/widgets/primary_button.dart b/lib/src/widgets/primary_button.dart index 9c995e7ad..286dbb494 100644 --- a/lib/src/widgets/primary_button.dart +++ b/lib/src/widgets/primary_button.dart @@ -11,7 +11,7 @@ class PrimaryButton extends StatelessWidget { this.isDisabled = false, this.isDottedBorder = false, this.borderColor = Colors.black, - this.radius, + this.radius = 26.0, this.onDisabledPressed}); final VoidCallback onPressed; @@ -45,9 +45,7 @@ class PrimaryButton extends StatelessWidget { style: TextStyle( fontSize: 15.0, fontWeight: FontWeight.w600, - color: isDisabled - ? textColor.withOpacity(0.5) - : textColor)), + color: isDisabled ? textColor.withOpacity(0.5) : textColor)), )); return isDottedBorder @@ -65,11 +63,11 @@ class PrimaryButton extends StatelessWidget { class LoadingPrimaryButton extends StatelessWidget { const LoadingPrimaryButton( {@required this.onPressed, - @required this.text, - @required this.color, - @required this.textColor, - this.isDisabled = false, - this.isLoading = false}); + @required this.text, + @required this.color, + @required this.textColor, + this.isDisabled = false, + this.isLoading = false}); final VoidCallback onPressed; final Color color; @@ -87,35 +85,32 @@ class LoadingPrimaryButton extends StatelessWidget { onPressed: (isLoading || isDisabled) ? null : onPressed, color: color, disabledColor: color.withOpacity(0.5), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(26.0)), + shape: + RoundedRectangleBorder(borderRadius: BorderRadius.circular(26.0)), child: isLoading ? CupertinoActivityIndicator(animating: true) : Text(text, - style: TextStyle( - fontSize: 15.0, - fontWeight: FontWeight.w600, - color: isDisabled - ? textColor.withOpacity(0.5) - : textColor - )), + style: TextStyle( + fontSize: 15.0, + fontWeight: FontWeight.w600, + color: + isDisabled ? textColor.withOpacity(0.5) : textColor)), )); } } class PrimaryIconButton extends StatelessWidget { - const PrimaryIconButton({ - @required this.onPressed, - @required this.iconData, - @required this.text, - @required this.color, - @required this.borderColor, - @required this.iconColor, - @required this.iconBackgroundColor, - @required this.textColor, - this.mainAxisAlignment = MainAxisAlignment.start, - this.radius = 26 - }); + const PrimaryIconButton( + {@required this.onPressed, + @required this.iconData, + @required this.text, + @required this.color, + @required this.borderColor, + @required this.iconColor, + @required this.iconBackgroundColor, + @required this.textColor, + this.mainAxisAlignment = MainAxisAlignment.start, + this.radius = 26}); final VoidCallback onPressed; final IconData iconData; @@ -150,8 +145,7 @@ class PrimaryIconButton extends StatelessWidget { decoration: BoxDecoration( shape: BoxShape.circle, color: iconBackgroundColor), child: Center( - child: Icon(iconData, color: iconColor, size: 22.0) - ), + child: Icon(iconData, color: iconColor, size: 22.0)), ), ], ), @@ -159,9 +153,7 @@ class PrimaryIconButton extends StatelessWidget { height: 52.0, child: Center( child: Text(text, - style: TextStyle( - fontSize: 16.0, - color: textColor)), + style: TextStyle(fontSize: 16.0, color: textColor)), ), ) ], @@ -192,28 +184,26 @@ class PrimaryImageButton extends StatelessWidget { minWidth: double.infinity, height: 52.0, child: FlatButton( - onPressed: onPressed, - color: color, - shape: RoundedRectangleBorder( - side: BorderSide(color: borderColor), - borderRadius: BorderRadius.circular(26.0)), - child:Center( - child: Row( - mainAxisSize: MainAxisSize.min, - children: <Widget>[ - image, - SizedBox(width: 15), - Text( - text, - style: TextStyle( - fontSize: 15, - fontWeight: FontWeight.w600, - color: textColor - ), - ) - ], - ), - ) - )); + onPressed: onPressed, + color: color, + shape: RoundedRectangleBorder( + side: BorderSide(color: borderColor), + borderRadius: BorderRadius.circular(26.0)), + child: Center( + child: Row( + mainAxisSize: MainAxisSize.min, + children: <Widget>[ + image, + SizedBox(width: 15), + Text( + text, + style: TextStyle( + fontSize: 15, + fontWeight: FontWeight.w600, + color: textColor), + ) + ], + ), + ))); } } diff --git a/lib/view_model/loan/loan_account_view_model.dart b/lib/view_model/loan/loan_account_view_model.dart new file mode 100644 index 000000000..53a00b5e0 --- /dev/null +++ b/lib/view_model/loan/loan_account_view_model.dart @@ -0,0 +1,36 @@ +import 'package:cake_wallet/view_model/loan/loan_item.dart'; +import 'package:cw_core/sync_status.dart'; +import 'package:cw_core/wallet_base.dart'; +import 'package:mobx/mobx.dart'; +part 'loan_account_view_model.g.dart'; + +class LoanAccountViewModel = LoanAccountViewModelBase + with _$LoanAccountViewModel; + +abstract class LoanAccountViewModelBase with Store { + LoanAccountViewModelBase({this.wallet}) { + isLoggedIn = false; + _fetchLoanItems(); + } + + final WalletBase wallet; + + @computed + bool get status => wallet.syncStatus is SyncedSyncStatus; + + @observable + bool isLoggedIn; + + @observable + List<LoanItem> items; + + Future<void> _fetchLoanItems() async { + await Future<void>.delayed(Duration(seconds: 5)); + isLoggedIn = true; + items = [ + LoanItem(id: '2133432', amount: 20000, status: 'Awaiting deposit'), + LoanItem(id: '2133432', amount: 20000, status: 'Awaiting deposit'), + LoanItem(id: '2133432', amount: 20000, status: 'Awaiting deposit') + ]; + } +} diff --git a/lib/view_model/loan/loan_detail_view_model.dart b/lib/view_model/loan/loan_detail_view_model.dart new file mode 100644 index 000000000..68e40d6d5 --- /dev/null +++ b/lib/view_model/loan/loan_detail_view_model.dart @@ -0,0 +1,13 @@ +import 'package:cake_wallet/view_model/loan/loan_item.dart'; +import 'package:mobx/mobx.dart'; +part 'loan_detail_view_model.g.dart'; + +class LoanDetailViewModel = LoanDetailViewModelBase with _$LoanDetailViewModel; + +abstract class LoanDetailViewModelBase with Store { + LoanDetailViewModelBase({LoanItem loanItem}) { + loanDetails = loanItem; + } + + LoanItem loanDetails; +} diff --git a/lib/view_model/loan/loan_item.dart b/lib/view_model/loan/loan_item.dart new file mode 100644 index 000000000..4a9eb8c73 --- /dev/null +++ b/lib/view_model/loan/loan_item.dart @@ -0,0 +1,6 @@ +class LoanItem { + LoanItem({this.id, this.amount, this.status}); + final String id; + final double amount; + final String status; +}