mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
* initial commit
* creating and restoring a wallet
* [skip ci] add transaction priority
* fix send and unspent screen
* fix transaction priority type
* replace Unspend with BitcoinUnspent
* add transaction creation
* fix transaction details screen
* minor fix
* fix create side wallet
* basic transaction creation flow
* fix fiat amount calculation
* edit wallet
* minor fix
* fix address book parsing
* merge commit fixes
* minor fixes
* Update gradle.properties
* fix bch unspent coins
* minor fix
* fix BitcoinCashTransactionPriority
* Fetch tags first before switching to one of them
* Update build_haven.sh
* Update build_haven.sh
* Update build_haven.sh
* Update build_haven.sh
* update transaction build function
* Update build_haven.sh
* add ability to rename and delete
* fix address format
* Update pubspec.lock
* Revert "fix address format"
This reverts commit 1549bf4d8c
.
* fix address format for exange
* restore from qr
* Update configure.dart
* [skip ci] minor fix
* fix default fee rate
* Update onramper_buy_provider.dart
* Update wallet_address_list_view_model.dart
* PR comments fixes
* Update exchange_view_model.dart
* fix merge conflict
* Update address_validator.dart
* merge fixes
* update initialMigrationVersion
* move cw_bitbox to Cake tech
* PR fixes
* PR fixes
* Fix configure.dart brackets
* update the new version text after macos
* dummy change to run workflow
* Fix Nano restore from QR issue
Fix Conflicts with main
* PR fixes
* Update app_config.sh
---------
Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
158 lines
5.6 KiB
Dart
158 lines
5.6 KiB
Dart
import 'package:cake_wallet/buy/moonpay/moonpay_buy_provider.dart';
|
|
import 'package:cake_wallet/buy/onramper/onramper_buy_provider.dart';
|
|
import 'package:cake_wallet/buy/robinhood/robinhood_buy_provider.dart';
|
|
import 'package:cake_wallet/di.dart';
|
|
import 'package:cake_wallet/entities/buy_provider_types.dart';
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
import 'package:cake_wallet/routes.dart';
|
|
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
|
|
import 'package:cake_wallet/utils/device_info.dart';
|
|
import 'package:cake_wallet/utils/show_pop_up.dart';
|
|
import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart';
|
|
import 'package:cw_core/wallet_type.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
class MainActions {
|
|
final String Function(BuildContext context) name;
|
|
final String image;
|
|
|
|
final bool Function(DashboardViewModel viewModel)? isEnabled;
|
|
final bool Function(DashboardViewModel viewModel)? canShow;
|
|
final Future<void> Function(BuildContext context, DashboardViewModel viewModel) onTap;
|
|
|
|
MainActions._({
|
|
required this.name,
|
|
required this.image,
|
|
this.isEnabled,
|
|
this.canShow,
|
|
required this.onTap,
|
|
});
|
|
|
|
static List<MainActions> all = [
|
|
buyAction,
|
|
receiveAction,
|
|
exchangeAction,
|
|
sendAction,
|
|
sellAction,
|
|
];
|
|
|
|
static MainActions buyAction = MainActions._(
|
|
name: (context) => S.of(context).buy,
|
|
image: 'assets/images/buy.png',
|
|
isEnabled: (viewModel) => viewModel.isEnabledBuyAction,
|
|
canShow: (viewModel) => viewModel.hasBuyAction,
|
|
onTap: (BuildContext context, DashboardViewModel viewModel) async {
|
|
final defaultBuyProvider = viewModel.defaultBuyProvider;
|
|
final walletType = viewModel.type;
|
|
|
|
if (!viewModel.isEnabledBuyAction) return;
|
|
|
|
switch (walletType) {
|
|
case WalletType.bitcoin:
|
|
case WalletType.litecoin:
|
|
case WalletType.ethereum:
|
|
case WalletType.bitcoinCash:
|
|
case WalletType.nano:
|
|
case WalletType.banano:
|
|
switch (defaultBuyProvider) {
|
|
case BuyProviderType.AskEachTime:
|
|
Navigator.pushNamed(context, Routes.buy);
|
|
break;
|
|
case BuyProviderType.Onramper:
|
|
await getIt.get<OnRamperBuyProvider>().launchProvider(context);
|
|
break;
|
|
case BuyProviderType.Robinhood:
|
|
await getIt.get<RobinhoodBuyProvider>().launchProvider(context);
|
|
break;
|
|
}
|
|
break;
|
|
case WalletType.monero:
|
|
await getIt.get<OnRamperBuyProvider>().launchProvider(context);
|
|
break;
|
|
default:
|
|
await showPopUp<void>(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertWithOneAction(
|
|
alertTitle: S.of(context).buy,
|
|
alertContent: S.of(context).unsupported_asset,
|
|
buttonText: S.of(context).ok,
|
|
buttonAction: () => Navigator.of(context).pop());
|
|
});
|
|
}
|
|
},
|
|
);
|
|
|
|
static MainActions receiveAction = MainActions._(
|
|
name: (context) => S.of(context).receive,
|
|
image: 'assets/images/received.png',
|
|
onTap: (BuildContext context, DashboardViewModel viewModel) async {
|
|
Navigator.pushNamed(context, Routes.addressPage);
|
|
},
|
|
);
|
|
|
|
static MainActions exchangeAction = MainActions._(
|
|
name: (context) => S.of(context).exchange,
|
|
image: 'assets/images/transfer.png',
|
|
isEnabled: (viewModel) => viewModel.isEnabledExchangeAction,
|
|
canShow: (viewModel) => viewModel.hasExchangeAction,
|
|
onTap: (BuildContext context, DashboardViewModel viewModel) async {
|
|
if (viewModel.isEnabledExchangeAction) {
|
|
await Navigator.of(context).pushNamed(Routes.exchange);
|
|
}
|
|
},
|
|
);
|
|
|
|
static MainActions sendAction = MainActions._(
|
|
name: (context) => S.of(context).send,
|
|
image: 'assets/images/upload.png',
|
|
onTap: (BuildContext context, DashboardViewModel viewModel) async {
|
|
Navigator.pushNamed(context, Routes.send);
|
|
},
|
|
);
|
|
|
|
static MainActions sellAction = MainActions._(
|
|
name: (context) => S.of(context).sell,
|
|
image: 'assets/images/sell.png',
|
|
isEnabled: (viewModel) => viewModel.isEnabledSellAction,
|
|
canShow: (viewModel) => viewModel.hasSellAction,
|
|
onTap: (BuildContext context, DashboardViewModel viewModel) async {
|
|
final walletType = viewModel.type;
|
|
|
|
switch (walletType) {
|
|
case WalletType.bitcoin:
|
|
case WalletType.litecoin:
|
|
case WalletType.ethereum:
|
|
case WalletType.bitcoinCash:
|
|
if (viewModel.isEnabledSellAction) {
|
|
final moonPaySellProvider = MoonPaySellProvider();
|
|
final uri = await moonPaySellProvider.requestUrl(
|
|
currency: viewModel.wallet.currency,
|
|
refundWalletAddress: viewModel.wallet.walletAddresses.address,
|
|
settingsStore: viewModel.settingsStore,
|
|
);
|
|
if (DeviceInfo.instance.isMobile) {
|
|
Navigator.of(context).pushNamed(Routes.webViewPage,
|
|
arguments: [S.of(context).sell, uri]);
|
|
} else {
|
|
await launchUrl(uri);
|
|
}
|
|
}
|
|
|
|
break;
|
|
default:
|
|
await showPopUp<void>(
|
|
context: context,
|
|
builder: (BuildContext context) {
|
|
return AlertWithOneAction(
|
|
alertTitle: S.of(context).sell,
|
|
alertContent: S.of(context).unsupported_asset,
|
|
buttonText: S.of(context).ok,
|
|
buttonAction: () => Navigator.of(context).pop());
|
|
},
|
|
);
|
|
}
|
|
},
|
|
);
|
|
}
|