mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-10-30 08:57:38 +00:00
b3d579c24a
* chore: Initial setup for polygon package * feat: Add polygon node urls * feat: Add Polygon(MATIC) wallet WIP * feat: Add Polygon(MATIC) wallet WIP * feat: Add Polygon MATIC wallet [skip ci] * fix: Issue with create/restore wallet for polygon * feat: Add erc20 tokens for polygon * feat: Adding Polygon MATIC Wallet * fix: Add build command for polygon to workflow file to fix failing action * fix: Switch evm to not display additional balance * chore: Sync with remote * fix: Revert change to inject app script * feat: Add polygon erc20 tokens * feat: Increase migration version * fix: Restore from QR address validator fix * fix: Adjust wallet connect connection flow to adapt to wallet type * fix: Make wallet fetch nfts based on the current wallet type * fix: Make wallet fetch nfts based on the current wallet type * fix: Try fetching transactions with moralis * fix: Requested review changes * fix: Error creating new wallet * fix: Revert script * fix: Exclude spam NFTs from nft listing API response * Update default_erc20_tokens.dart * replace matic with matic poly * Add polygon wallet scheme to app links * style: reformat default_settings_migration.dart * minor enhancement * fix using different wallet function for setting the transaction priorities * fix: Add chain to calls * Add USDC.e to initial coins * Add other default polygon node * Use Polygon scan some UI fixes * Add polygon scan api key to secrets generation code --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
161 lines
5.7 KiB
Dart
161 lines
5.7 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.polygon:
|
|
case WalletType.bitcoinCash:
|
|
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.nano:
|
|
case WalletType.banano:
|
|
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.polygon:
|
|
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());
|
|
},
|
|
);
|
|
}
|
|
},
|
|
);
|
|
}
|