mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
ebe8c65407
* version 4.20.0 * update build numbers * UI updates and script fix for ios bundle identifier * disable mweb for desktop * change hardcoded ltc server ip address electrum connection enhancement * additional logging and minor fixes * additional logging and minor fixes * addresses pt.1 * logs of fixes and experimental changes, close wallet before opening next * save * fix icon * fixes * [skip ci] updates * [skip ci] updates * updates * minor optimizations * fix for when switching between wallets * [skip ci] updates * [skip ci] updates * Update cw_bitcoin/lib/litecoin_wallet.dart Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * Update cw_bitcoin/lib/litecoin_wallet.dart Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * mobx * mostly logging * stream fix pt.1 [skip ci] * updates * some fixes and enhancements * [skip ci] minor * potential partial fix for streamsink closed * fix stream sink closed errors * fix mweb logo colors * add initial whitelisting for coin types on send screen * MWEB enhancements 2.0 (#1735) * additional logging and minor fixes * additional logging and minor fixes * addresses pt.1 * Allow Wallet Group Names to be the same as Wallet Names (#1730) * fix: Issues with imaging * fix: Allow group names to be the same as wallet names * fix: Bug with wallet grouping when a wallet is minimized * fix: Bug with wallet grouping when a wallet is minimized * logs of fixes and experimental changes, close wallet before opening next * save * fix icon * fixes * [skip ci] updates * [skip ci] updates * updates * minor optimizations * fix for when switching between wallets * [skip ci] updates * [skip ci] updates * Update cw_bitcoin/lib/litecoin_wallet.dart Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * Update cw_bitcoin/lib/litecoin_wallet.dart Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * mobx * mostly logging * stream fix pt.1 [skip ci] * updates * some fixes and enhancements * [skip ci] minor * potential partial fix for streamsink closed * fix stream sink closed errors * fix mweb logo colors * save * minor enhancements [skip ci] * save * experimental * minor * minor [skip ci] --------- Co-authored-by: David Adegoke <64401859+Blazebrain@users.noreply.github.com> Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com> * fix menu list removing from original list * handle pegin and pegout * fix text color * fix import * pegin/out button ui updates * update spacing + tx creation fix * add correct args for link view model [skip ci] --------- Co-authored-by: Matthew Fosse <matt@fosse.co> Co-authored-by: fossephate <matt.cfosse@gmail.com> Co-authored-by: David Adegoke <64401859+Blazebrain@users.noreply.github.com>
114 lines
3 KiB
Dart
114 lines
3 KiB
Dart
import 'package:cake_wallet/generated/i18n.dart';
|
|
import 'package:cake_wallet/reactions/wallet_connect.dart';
|
|
import 'package:cake_wallet/routes.dart';
|
|
import 'package:cake_wallet/store/app_store.dart';
|
|
import 'package:cake_wallet/store/authentication_store.dart';
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
|
import 'package:cake_wallet/utils/payment_request.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
class LinkViewModel {
|
|
LinkViewModel({
|
|
required this.settingsStore,
|
|
required this.appStore,
|
|
required this.authenticationStore,
|
|
required this.navigatorKey,
|
|
});
|
|
|
|
final SettingsStore settingsStore;
|
|
final AppStore appStore;
|
|
final AuthenticationStore authenticationStore;
|
|
final GlobalKey<NavigatorState> navigatorKey;
|
|
Uri? currentLink;
|
|
|
|
bool get _isValidPaymentUri => currentLink?.path.isNotEmpty ?? false;
|
|
bool get isWalletConnectLink => currentLink?.authority == 'wc';
|
|
bool get isNanoGptLink => currentLink?.scheme == 'nano-gpt';
|
|
|
|
String? getRouteToGo() {
|
|
if (isWalletConnectLink) {
|
|
if (!isEVMCompatibleChain(appStore.wallet!.type)) {
|
|
_errorToast(S.current.switchToEVMCompatibleWallet);
|
|
return null;
|
|
}
|
|
return Routes.walletConnectConnectionsListing;
|
|
}
|
|
|
|
if (authenticationStore.state == AuthenticationState.uninitialized) {
|
|
return null;
|
|
}
|
|
|
|
if (isNanoGptLink) {
|
|
switch (currentLink?.authority ?? '') {
|
|
case "exchange":
|
|
return Routes.exchange;
|
|
case "send":
|
|
return Routes.send;
|
|
case "buy":
|
|
return Routes.buySellPage;
|
|
}
|
|
}
|
|
|
|
if (_isValidPaymentUri) {
|
|
return Routes.send;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
dynamic getRouteArgs() {
|
|
if (isWalletConnectLink) {
|
|
return currentLink;
|
|
}
|
|
|
|
if (isNanoGptLink) {
|
|
switch (currentLink?.authority ?? '') {
|
|
case "exchange":
|
|
return PaymentRequest.fromUri(currentLink);
|
|
case "send":
|
|
return {"paymentRequest": PaymentRequest.fromUri(currentLink)};
|
|
case "buy":
|
|
return true;
|
|
}
|
|
}
|
|
|
|
if (_isValidPaymentUri) {
|
|
return {"paymentRequest": PaymentRequest.fromUri(currentLink)};
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
Future<void> _errorToast(String message, {double fontSize = 16}) async {
|
|
Fluttertoast.showToast(
|
|
msg: message,
|
|
toastLength: Toast.LENGTH_LONG,
|
|
gravity: ToastGravity.SNACKBAR,
|
|
backgroundColor: Colors.black,
|
|
textColor: Colors.white,
|
|
fontSize: fontSize,
|
|
);
|
|
}
|
|
|
|
Future<void> handleLink() async {
|
|
String? route = getRouteToGo();
|
|
dynamic args = getRouteArgs();
|
|
if (route != null) {
|
|
if (appStore.wallet == null) {
|
|
return;
|
|
}
|
|
|
|
if (isNanoGptLink) {
|
|
if (route == Routes.buySellPage || route == Routes.exchange) {
|
|
await _errorToast(S.current.nano_gpt_thanks_message, fontSize: 14);
|
|
}
|
|
}
|
|
currentLink = null;
|
|
navigatorKey.currentState?.pushNamed(
|
|
route,
|
|
arguments: args,
|
|
);
|
|
}
|
|
}
|
|
}
|