mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-18 05:51:34 +02:00
Merge branch 'main' into fix-trade-datails-screen-for-SideShift
This commit is contained in:
@@ -11,6 +11,7 @@ class PreferencesKey {
|
||||
static const shouldSaveRecipientAddressKey = 'save_recipient_address';
|
||||
static const allowBiometricalAuthenticationKey =
|
||||
'allow_biometrical_authentication';
|
||||
static const disableExchangeKey = 'disable_exchange';
|
||||
static const currentTheme = 'current_theme';
|
||||
static const isDarkThemeLegacy = 'dark_theme';
|
||||
static const displayActionListModeKey = 'display_list_mode';
|
||||
|
||||
@@ -315,6 +315,8 @@ class DashboardPage extends BasePage {
|
||||
}
|
||||
|
||||
Future<void> _onClickExchangeButton(BuildContext context) async {
|
||||
await Navigator.of(context).pushNamed(Routes.exchange);
|
||||
if (walletViewModel.isEnabledExchangeAction) {
|
||||
await Navigator.of(context).pushNamed(Routes.exchange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ class QrPainter extends CustomPainter {
|
||||
this.errorCorrectionLevel,
|
||||
) : this._qr = QrCode(version, errorCorrectionLevel)..addData(data) {
|
||||
_p.color = this.color;
|
||||
_qr.addData(data);
|
||||
_qrImage = QrImage(_qr);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ abstract class SettingsStoreBase with Store {
|
||||
required BalanceDisplayMode initialBalanceDisplayMode,
|
||||
required bool initialSaveRecipientAddress,
|
||||
required bool initialAllowBiometricalAuthentication,
|
||||
required bool initialExchangeEnabled,
|
||||
required ThemeBase initialTheme,
|
||||
required int initialPinLength,
|
||||
required String initialLanguageCode,
|
||||
@@ -47,6 +48,7 @@ abstract class SettingsStoreBase with Store {
|
||||
balanceDisplayMode = initialBalanceDisplayMode,
|
||||
shouldSaveRecipientAddress = initialSaveRecipientAddress,
|
||||
allowBiometricalAuthentication = initialAllowBiometricalAuthentication,
|
||||
disableExchange = initialExchangeEnabled,
|
||||
currentTheme = initialTheme,
|
||||
pinCodeLength = initialPinLength,
|
||||
languageCode = initialLanguageCode,
|
||||
@@ -143,6 +145,9 @@ abstract class SettingsStoreBase with Store {
|
||||
@observable
|
||||
bool allowBiometricalAuthentication;
|
||||
|
||||
@observable
|
||||
bool disableExchange;
|
||||
|
||||
@observable
|
||||
ThemeBase currentTheme;
|
||||
|
||||
@@ -221,6 +226,8 @@ abstract class SettingsStoreBase with Store {
|
||||
final allowBiometricalAuthentication = sharedPreferences
|
||||
.getBool(PreferencesKey.allowBiometricalAuthenticationKey) ??
|
||||
false;
|
||||
final disableExchange = sharedPreferences
|
||||
.getBool(PreferencesKey.disableExchangeKey) ?? false;
|
||||
final legacyTheme =
|
||||
(sharedPreferences.getBool(PreferencesKey.isDarkThemeLegacy) ?? false)
|
||||
? ThemeType.dark.index
|
||||
@@ -284,6 +291,7 @@ abstract class SettingsStoreBase with Store {
|
||||
initialBalanceDisplayMode: currentBalanceDisplayMode,
|
||||
initialSaveRecipientAddress: shouldSaveRecipientAddress,
|
||||
initialAllowBiometricalAuthentication: allowBiometricalAuthentication,
|
||||
initialExchangeEnabled: disableExchange,
|
||||
initialTheme: savedTheme,
|
||||
actionlistDisplayMode: actionListDisplayMode,
|
||||
initialPinLength: pinLength,
|
||||
|
||||
@@ -53,7 +53,6 @@ abstract class DashboardViewModelBase with Store {
|
||||
hasBuyAction = false,
|
||||
isEnabledBuyAction = false,
|
||||
hasExchangeAction = false,
|
||||
isEnabledExchangeAction = false,
|
||||
isShowFirstYatIntroduction = false,
|
||||
isShowSecondYatIntroduction = false,
|
||||
isShowThirdYatIntroduction = false,
|
||||
@@ -249,8 +248,8 @@ abstract class DashboardViewModelBase with Store {
|
||||
void furtherShowYatPopup(bool shouldShow) =>
|
||||
settingsStore.shouldShowYatPopup = shouldShow;
|
||||
|
||||
@observable
|
||||
bool isEnabledExchangeAction;
|
||||
@computed
|
||||
bool get isEnabledExchangeAction => !settingsStore.disableExchange;
|
||||
|
||||
@observable
|
||||
bool hasExchangeAction;
|
||||
@@ -365,7 +364,6 @@ abstract class DashboardViewModelBase with Store {
|
||||
}
|
||||
|
||||
void updateActions() {
|
||||
isEnabledExchangeAction = true;
|
||||
hasExchangeAction = !isHaven;
|
||||
isEnabledBuyAction = wallet.type != WalletType.haven
|
||||
&& wallet.type != WalletType.monero;
|
||||
|
||||
@@ -7,7 +7,6 @@ import 'package:cake_wallet/exchange/sideshift/sideshift_exchange_provider.dart'
|
||||
import 'package:cake_wallet/exchange/sideshift/sideshift_request.dart';
|
||||
import 'package:cake_wallet/exchange/simpleswap/simpleswap_exchange_provider.dart';
|
||||
import 'package:cake_wallet/view_model/settings/settings_view_model.dart';
|
||||
import 'package:cw_core/transaction_priority.dart';
|
||||
import 'package:cake_wallet/exchange/simpleswap/simpleswap_request.dart';
|
||||
import 'package:cw_core/wallet_base.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
@@ -375,96 +374,105 @@ abstract class ExchangeViewModelBase with Store {
|
||||
TradeRequest? request;
|
||||
String amount = '';
|
||||
|
||||
for (var provider in _sortedAvailableProviders.values) {
|
||||
if (!(await provider.checkIsAvailable())) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
for (var provider in _sortedAvailableProviders.values) {
|
||||
if (!(await provider.checkIsAvailable())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (provider is SideShiftExchangeProvider) {
|
||||
request = SideShiftRequest(
|
||||
depositMethod: depositCurrency,
|
||||
settleMethod: receiveCurrency,
|
||||
depositAmount: depositAmount.replaceAll(',', '.'),
|
||||
settleAddress: receiveAddress,
|
||||
refundAddress: depositAddress,
|
||||
);
|
||||
amount = depositAmount;
|
||||
}
|
||||
if (provider is SideShiftExchangeProvider) {
|
||||
request = SideShiftRequest(
|
||||
depositMethod: depositCurrency,
|
||||
settleMethod: receiveCurrency,
|
||||
depositAmount: depositAmount.replaceAll(',', '.'),
|
||||
settleAddress: receiveAddress,
|
||||
refundAddress: depositAddress,
|
||||
);
|
||||
amount = depositAmount;
|
||||
}
|
||||
|
||||
if (provider is SimpleSwapExchangeProvider) {
|
||||
request = SimpleSwapRequest(
|
||||
from: depositCurrency,
|
||||
to: receiveCurrency,
|
||||
amount: depositAmount.replaceAll(',', '.'),
|
||||
address: receiveAddress,
|
||||
refundAddress: depositAddress,
|
||||
);
|
||||
amount = depositAmount;
|
||||
}
|
||||
|
||||
if (provider is XMRTOExchangeProvider) {
|
||||
request = XMRTOTradeRequest(
|
||||
if (provider is SimpleSwapExchangeProvider) {
|
||||
request = SimpleSwapRequest(
|
||||
from: depositCurrency,
|
||||
to: receiveCurrency,
|
||||
amount: depositAmount.replaceAll(',', '.'),
|
||||
receiveAmount: receiveAmount.replaceAll(',', '.'),
|
||||
address: receiveAddress,
|
||||
refundAddress: depositAddress,
|
||||
isBTCRequest: isReceiveAmountEntered);
|
||||
amount = depositAmount;
|
||||
}
|
||||
);
|
||||
amount = depositAmount;
|
||||
}
|
||||
|
||||
if (provider is ChangeNowExchangeProvider) {
|
||||
request = ChangeNowRequest(
|
||||
from: depositCurrency,
|
||||
to: receiveCurrency,
|
||||
fromAmount: depositAmount.replaceAll(',', '.'),
|
||||
toAmount: receiveAmount.replaceAll(',', '.'),
|
||||
refundAddress: depositAddress,
|
||||
address: receiveAddress,
|
||||
isReverse: isReverse);
|
||||
amount = isReverse ? receiveAmount : depositAmount;
|
||||
}
|
||||
if (provider is XMRTOExchangeProvider) {
|
||||
request = XMRTOTradeRequest(
|
||||
from: depositCurrency,
|
||||
to: receiveCurrency,
|
||||
amount: depositAmount.replaceAll(',', '.'),
|
||||
receiveAmount: receiveAmount.replaceAll(',', '.'),
|
||||
address: receiveAddress,
|
||||
refundAddress: depositAddress,
|
||||
isBTCRequest: isReceiveAmountEntered);
|
||||
amount = depositAmount;
|
||||
}
|
||||
|
||||
if (provider is MorphTokenExchangeProvider) {
|
||||
request = MorphTokenRequest(
|
||||
from: depositCurrency,
|
||||
to: receiveCurrency,
|
||||
amount: depositAmount.replaceAll(',', '.'),
|
||||
refundAddress: depositAddress,
|
||||
address: receiveAddress);
|
||||
amount = depositAmount;
|
||||
}
|
||||
if (provider is ChangeNowExchangeProvider) {
|
||||
request = ChangeNowRequest(
|
||||
from: depositCurrency,
|
||||
to: receiveCurrency,
|
||||
fromAmount: depositAmount.replaceAll(',', '.'),
|
||||
toAmount: receiveAmount.replaceAll(',', '.'),
|
||||
refundAddress: depositAddress,
|
||||
address: receiveAddress,
|
||||
isReverse: isReverse);
|
||||
amount = isReverse ? receiveAmount : depositAmount;
|
||||
}
|
||||
|
||||
amount = amount.replaceAll(',', '.');
|
||||
if (provider is MorphTokenExchangeProvider) {
|
||||
request = MorphTokenRequest(
|
||||
from: depositCurrency,
|
||||
to: receiveCurrency,
|
||||
amount: depositAmount.replaceAll(',', '.'),
|
||||
refundAddress: depositAddress,
|
||||
address: receiveAddress);
|
||||
amount = depositAmount;
|
||||
}
|
||||
|
||||
if (limitsState is LimitsLoadedSuccessfully) {
|
||||
if (double.parse(amount) < limits.min!) {
|
||||
continue;
|
||||
} else if (limits.max != null && double.parse(amount) > limits.max!) {
|
||||
continue;
|
||||
} else {
|
||||
try {
|
||||
tradeState = TradeIsCreating();
|
||||
final trade = await provider.createTrade(
|
||||
request: request!, isFixedRateMode: isFixedRateMode);
|
||||
trade.walletId = wallet.id;
|
||||
tradesStore.setTrade(trade);
|
||||
await trades.add(trade);
|
||||
tradeState = TradeIsCreatedSuccessfully(trade: trade);
|
||||
/// return after the first successful trade
|
||||
return;
|
||||
} catch (e) {
|
||||
amount = amount.replaceAll(',', '.');
|
||||
|
||||
if (limitsState is LimitsLoadedSuccessfully) {
|
||||
if (double.parse(amount) < limits.min!) {
|
||||
continue;
|
||||
} else if (limits.max != null && double.parse(amount) > limits.max!) {
|
||||
continue;
|
||||
} else {
|
||||
try {
|
||||
tradeState = TradeIsCreating();
|
||||
final trade = await provider.createTrade(
|
||||
request: request!, isFixedRateMode: isFixedRateMode);
|
||||
trade.walletId = wallet.id;
|
||||
tradesStore.setTrade(trade);
|
||||
await trades.add(trade);
|
||||
tradeState = TradeIsCreatedSuccessfully(trade: trade);
|
||||
/// return after the first successful trade
|
||||
return;
|
||||
} catch (e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// if the code reached here then none of the providers succeeded
|
||||
tradeState = TradeIsCreatedFailure(
|
||||
title: S.current.trade_not_created,
|
||||
error: S.current.none_of_selected_providers_can_exchange);
|
||||
/// if the code reached here then none of the providers succeeded
|
||||
tradeState = TradeIsCreatedFailure(
|
||||
title: S.current.trade_not_created,
|
||||
error: S.current.none_of_selected_providers_can_exchange);
|
||||
} on ConcurrentModificationError {
|
||||
/// if create trade happened at the exact same time of the scheduled rate update
|
||||
/// then delay the create trade a bit and try again
|
||||
///
|
||||
/// this is because the limitation of the SplayTreeMap that
|
||||
/// you can't modify it while iterating through it
|
||||
Future.delayed(Duration(milliseconds: 500), createTrade);
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
|
||||
@@ -208,6 +208,12 @@ abstract class SettingsViewModelBase with Store {
|
||||
setAllowBiometricalAuthentication(value);
|
||||
}
|
||||
}),
|
||||
SwitcherListItem(
|
||||
title: S.current.disable_exchange,
|
||||
value: () => _settingsStore.disableExchange,
|
||||
onValueChange: (BuildContext context, bool value) {
|
||||
_settingsStore.disableExchange = value;
|
||||
}),
|
||||
ChoicesListItem(
|
||||
title: S.current.color_theme,
|
||||
items: ThemeList.all,
|
||||
|
||||
Reference in New Issue
Block a user