CAKE-360 | added shouldShowYatPopup parameter to settings_store.dart and applied this parameter to dashboard_view_model.dart and dashboard_page.dart; added scrollbar to choose_yat_address_alert.dart; changed yat logo; fixed fetchYatAddress() method in the yat_store.dart; created class YatLink

This commit is contained in:
OleksandrSobol 2021-10-04 16:03:35 +03:00
parent f353442a2a
commit c728931b70
10 changed files with 167 additions and 79 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 7.6 KiB

View file

@ -20,4 +20,5 @@ class PreferencesKey {
static const moneroTransactionPriority = 'current_fee_priority_monero'; static const moneroTransactionPriority = 'current_fee_priority_monero';
static const bitcoinTransactionPriority = 'current_fee_priority_bitcoin'; static const bitcoinTransactionPriority = 'current_fee_priority_bitcoin';
static const shouldShowReceiveWarning = 'should_show_receive_warning'; static const shouldShowReceiveWarning = 'should_show_receive_warning';
static const shouldShowYatPopup = 'should_show_yat_popup';
} }

View file

@ -156,6 +156,7 @@ class DashboardPage extends BasePage {
pages.add(BalancePage(dashboardViewModel: walletViewModel)); pages.add(BalancePage(dashboardViewModel: walletViewModel));
pages.add(TransactionsPage(dashboardViewModel: walletViewModel)); pages.add(TransactionsPage(dashboardViewModel: walletViewModel));
if (walletViewModel.shouldShowYatPopup) {
await Future<void>.delayed(Duration(seconds: 1)); await Future<void>.delayed(Duration(seconds: 1));
await showPopUp<void>( await showPopUp<void>(
context: context, context: context,
@ -164,6 +165,8 @@ class DashboardPage extends BasePage {
dashboardViewModel: walletViewModel, dashboardViewModel: walletViewModel,
onClose: () => Navigator.of(context).pop()); onClose: () => Navigator.of(context).pop());
}); });
walletViewModel.furtherShowYatPopup(false);
}
autorun((_) async { autorun((_) async {
if (!walletViewModel.isOutdatedElectrumWallet) { if (!walletViewModel.isOutdatedElectrumWallet) {

View file

@ -1,3 +1,4 @@
import 'package:cake_wallet/src/widgets/cake_scrollbar.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:cake_wallet/src/widgets/base_alert_dialog.dart'; import 'package:cake_wallet/src/widgets/base_alert_dialog.dart';
@ -22,14 +23,53 @@ class ChooseYatAddressAlert extends BaseAlertDialog {
bool get barrierDismissible => false; bool get barrierDismissible => false;
@override @override
Widget actionButtons(BuildContext context) { Widget actionButtons(BuildContext context) =>
return Container( ChooseYatAddressButtons(addresses);
}
class ChooseYatAddressButtons extends StatefulWidget {
ChooseYatAddressButtons(this.addresses);
final List<String> addresses;
@override
ChooseYatAddressButtonsState createState() =>
ChooseYatAddressButtonsState(addresses);
}
class ChooseYatAddressButtonsState extends State<ChooseYatAddressButtons> {
ChooseYatAddressButtonsState(this.addresses)
: itemCount = addresses?.length ?? 0;
final List<String> addresses;
final int itemCount;
final double backgroundHeight = 118;
final double thumbHeight = 72;
ScrollController controller = ScrollController();
double fromTop = 0;
@override
Widget build(BuildContext context) {
controller.addListener(() {
fromTop = controller.hasClients
? (controller.offset / controller.position.maxScrollExtent *
(backgroundHeight - thumbHeight))
: 0;
setState(() {});
});
return Stack(
alignment: Alignment.center,
clipBehavior: Clip.none,
children: [
Container(
width: 300, width: 300,
height: 105, height: 158,
color: Theme.of(context).accentTextTheme.body1.backgroundColor, color: Theme.of(context).accentTextTheme.body1.backgroundColor,
child: ListView.separated( child: ListView.separated(
controller: controller,
padding: EdgeInsets.all(0), padding: EdgeInsets.all(0),
itemCount: addresses.length, itemCount: itemCount,
separatorBuilder: (_, __) => Container( separatorBuilder: (_, __) => Container(
height: 1, height: 1,
color: Theme.of(context).dividerColor, color: Theme.of(context).dividerColor,
@ -67,6 +107,14 @@ class ChooseYatAddressAlert extends BaseAlertDialog {
), ),
); );
}) })
),
if (itemCount > 3) CakeScrollbar(
backgroundHeight: backgroundHeight,
thumbHeight: thumbHeight,
fromTop: fromTop,
//rightOffset: -15
)
]
); );
} }
} }

View file

@ -5,7 +5,7 @@ class YatBar extends StatelessWidget {
YatBar({this.onClose}); YatBar({this.onClose});
final VoidCallback onClose; final VoidCallback onClose;
final image = Image.asset('assets/images/yat_logo.png'); final image = Image.asset('assets/images/yat_logo.png', width: 81, height: 28);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View file

@ -11,7 +11,9 @@ import 'package:lottie/lottie.dart';
class YatAlert extends StatelessWidget { class YatAlert extends StatelessWidget {
YatAlert(this.yatStore) YatAlert(this.yatStore)
: baseUrl = isYatDevMode ? baseDevUrl : baseReleaseUrl; : baseUrl = YatLink.isDevMode
? YatLink.baseDevUrl
: YatLink.baseReleaseUrl;
final YatStore yatStore; final YatStore yatStore;
final String baseUrl; final String baseUrl;
@ -86,7 +88,7 @@ class YatAlert extends StatelessWidget {
.arrow_up_right_square, .arrow_up_right_square,
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
onPressed: () { onPressed: () {
final url = baseUrl + createSuffix; final url = baseUrl + YatLink.createSuffix;
launch(url); launch(url);
}), }),
Padding( Padding(
@ -102,11 +104,11 @@ class YatAlert extends StatelessWidget {
.arrow_up_right_square, .arrow_up_right_square,
mainAxisAlignment: MainAxisAlignment.end, mainAxisAlignment: MainAxisAlignment.end,
onPressed: () { onPressed: () {
String url = baseUrl + signInSuffix; String url = baseUrl + YatLink.signInSuffix;
final parameters = final parameters =
yatStore.defineQueryParameters(); yatStore.defineQueryParameters();
if (parameters.isNotEmpty) { if (parameters.isNotEmpty) {
url += queryParameter + parameters; url += YatLink.queryParameter + parameters;
} }
launch(url); launch(url);
}) })

View file

@ -14,7 +14,9 @@ import 'package:url_launcher/url_launcher.dart';
class YatPopup extends StatelessWidget { class YatPopup extends StatelessWidget {
YatPopup({this.dashboardViewModel, this.onClose}) YatPopup({this.dashboardViewModel, this.onClose})
: baseUrl = isYatDevMode ? baseDevUrl : baseReleaseUrl; : baseUrl = YatLink.isDevMode
? YatLink.baseDevUrl
: YatLink.baseReleaseUrl;
static const durationInMilliseconds = 250; static const durationInMilliseconds = 250;
@ -157,15 +159,15 @@ class YatPopup extends StatelessWidget {
child: ThirdIntroduction( child: ThirdIntroduction(
onClose: onClose, onClose: onClose,
onGet: () { onGet: () {
final url = baseUrl + createSuffix; final url = baseUrl + YatLink.createSuffix;
launch(url); launch(url);
}, },
onConnect: () { onConnect: () {
String url = baseUrl + signInSuffix; String url = baseUrl + YatLink.signInSuffix;
final parameters = dashboardViewModel final parameters = dashboardViewModel
.yatStore.defineQueryParameters(); .yatStore.defineQueryParameters();
if (parameters.isNotEmpty) { if (parameters.isNotEmpty) {
url += queryParameter + parameters; url += YatLink.queryParameter + parameters;
} }
launch(url); launch(url);
} }

View file

@ -38,6 +38,7 @@ abstract class SettingsStoreBase with Store {
@required Map<WalletType, Node> nodes, @required Map<WalletType, Node> nodes,
@required TransactionPriority initialBitcoinTransactionPriority, @required TransactionPriority initialBitcoinTransactionPriority,
@required TransactionPriority initialMoneroTransactionPriority, @required TransactionPriority initialMoneroTransactionPriority,
@required this.shouldShowYatPopup,
@required this.isBitcoinBuyEnabled, @required this.isBitcoinBuyEnabled,
this.actionlistDisplayMode}) { this.actionlistDisplayMode}) {
fiatCurrency = initialFiatCurrency; fiatCurrency = initialFiatCurrency;
@ -59,6 +60,11 @@ abstract class SettingsStoreBase with Store {
(FiatCurrency fiatCurrency) => sharedPreferences.setString( (FiatCurrency fiatCurrency) => sharedPreferences.setString(
PreferencesKey.currentFiatCurrencyKey, fiatCurrency.serialize())); PreferencesKey.currentFiatCurrencyKey, fiatCurrency.serialize()));
reaction(
(_) => shouldShowYatPopup,
(bool shouldShowYatPopup) => sharedPreferences
.setBool(PreferencesKey.shouldShowYatPopup, shouldShowYatPopup));
priority.observe((change) { priority.observe((change) {
final key = change.key == WalletType.monero final key = change.key == WalletType.monero
? PreferencesKey.moneroTransactionPriority ? PreferencesKey.moneroTransactionPriority
@ -110,6 +116,9 @@ abstract class SettingsStoreBase with Store {
@observable @observable
FiatCurrency fiatCurrency; FiatCurrency fiatCurrency;
@observable
bool shouldShowYatPopup;
@observable @observable
ObservableList<ActionListDisplayMode> actionlistDisplayMode; ObservableList<ActionListDisplayMode> actionlistDisplayMode;
@ -217,6 +226,8 @@ abstract class SettingsStoreBase with Store {
final bitcoinElectrumServer = nodeSource.get(bitcoinElectrumServerId); final bitcoinElectrumServer = nodeSource.get(bitcoinElectrumServerId);
final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId); final litecoinElectrumServer = nodeSource.get(litecoinElectrumServerId);
final packageInfo = await PackageInfo.fromPlatform(); final packageInfo = await PackageInfo.fromPlatform();
final shouldShowYatPopup =
sharedPreferences.getBool(PreferencesKey.shouldShowYatPopup) ?? true;
return SettingsStore( return SettingsStore(
sharedPreferences: sharedPreferences, sharedPreferences: sharedPreferences,
@ -236,7 +247,8 @@ abstract class SettingsStoreBase with Store {
initialPinLength: pinLength, initialPinLength: pinLength,
initialLanguageCode: savedLanguageCode, initialLanguageCode: savedLanguageCode,
initialMoneroTransactionPriority: moneroTransactionPriority, initialMoneroTransactionPriority: moneroTransactionPriority,
initialBitcoinTransactionPriority: bitcoinTransactionPriority); initialBitcoinTransactionPriority: bitcoinTransactionPriority,
shouldShowYatPopup: shouldShowYatPopup);
} }
Future<void> reload( Future<void> reload(
@ -270,6 +282,7 @@ abstract class SettingsStoreBase with Store {
pinCodeLength = settings.pinCodeLength; pinCodeLength = settings.pinCodeLength;
languageCode = settings.languageCode; languageCode = settings.languageCode;
appVersion = settings.appVersion; appVersion = settings.appVersion;
shouldShowYatPopup = settings.shouldShowYatPopup;
} }
Future<void> _saveCurrentNode(Node node, WalletType walletType) async { Future<void> _saveCurrentNode(Node node, WalletType walletType) async {

View file

@ -15,18 +15,24 @@ import 'package:http/http.dart';
part 'yat_store.g.dart'; part 'yat_store.g.dart';
const baseDevUrl = 'https://yat.fyi'; class YatLink {
const baseReleaseUrl = 'https://y.at'; static const baseDevUrl = 'https://yat.fyi';
const signInSuffix = '/partner/CW/link-email'; static const baseReleaseUrl = 'https://y.at';
const createSuffix = '/create'; static const signInSuffix = '/partner/CW/link-email';
const queryParameter = '?addresses='; static const createSuffix = '/create';
const requestDevUrl = 'https://a.yat.fyi/emoji_id/'; static const queryParameter = '?addresses=';
const requestReleaseUrl = 'https://a.y.at/emoji_id/'; static const requestDevUrl = 'https://a.yat.fyi/emoji_id/';
const isYatDevMode = true; static const requestReleaseUrl = 'https://a.y.at/emoji_id/';
static const isDevMode = true;
static const tags = <String, List<String>>{"XMR" : ['0x1001', '0x1002'],
"BTC" : ['0x1003'], "LTC" : ['0x3fff']};
}
Future<List<String>> fetchYatAddress(String emojiId, String ticker) async { Future<List<String>> fetchYatAddress(String emojiId, String ticker) async {
final requestURL = isYatDevMode ? requestDevUrl : requestReleaseUrl; final requestURL = YatLink.isDevMode
final url = requestURL + emojiId + '/' + ticker.toUpperCase(); ? YatLink.requestDevUrl
: YatLink.requestReleaseUrl;
final url = requestURL + emojiId;
final response = await get(url); final response = await get(url);
if (response.statusCode != 200) { if (response.statusCode != 200) {
@ -41,13 +47,20 @@ Future<List<String>> fetchYatAddress(String emojiId, String ticker) async {
} }
final List<String> addresses = []; final List<String> addresses = [];
final currency = ticker.toUpperCase();
for (var elem in result) { for (var elem in result) {
final tag = elem['tag'] as String;
if (tag?.isEmpty ?? true) {
continue;
}
if (YatLink.tags[currency]?.contains(tag) ?? false) {
final yatAddress = elem['data'] as String; final yatAddress = elem['data'] as String;
if (yatAddress?.isNotEmpty ?? false) { if (yatAddress?.isNotEmpty ?? false) {
addresses.add(yatAddress); addresses.add(yatAddress);
} }
} }
}
return addresses; return addresses;
} }
@ -123,8 +136,8 @@ abstract class YatStoreBase with Store {
} }
parameters += subaddress.address.startsWith('4') parameters += subaddress.address.startsWith('4')
? '0x1001%3D' ? YatLink.tags["XMR"].first + '%3D'
: '0x1002%3D'; : YatLink.tags["XMR"].last + '%3D';
parameters += subaddress.address; parameters += subaddress.address;
}); });
@ -141,7 +154,7 @@ abstract class YatStoreBase with Store {
isFirstAddress = !isFirstAddress; isFirstAddress = !isFirstAddress;
} }
parameters += '0x1003%3D' + record.address; parameters += YatLink.tags["BTC"].first + '%3D' + record.address;
}); });
break; break;
case WalletType.litecoin: case WalletType.litecoin:
@ -155,7 +168,7 @@ abstract class YatStoreBase with Store {
isFirstAddress = !isFirstAddress; isFirstAddress = !isFirstAddress;
} }
parameters += '0x3fff%3D' + record.address; parameters += YatLink.tags["LTC"].first + '%3D' + record.address;
}); });
break; break;
default: default:

View file

@ -236,6 +236,12 @@ abstract class DashboardViewModelBase with Store {
bool get isBuyEnabled => settingsStore.isBitcoinBuyEnabled; bool get isBuyEnabled => settingsStore.isBitcoinBuyEnabled;
bool get shouldShowYatPopup => settingsStore.shouldShowYatPopup;
@action
void furtherShowYatPopup(bool shouldShow) =>
settingsStore.shouldShowYatPopup = shouldShow;
ReactionDisposer _onMoneroAccountChangeReaction; ReactionDisposer _onMoneroAccountChangeReaction;
ReactionDisposer _onMoneroBalanceChangeReaction; ReactionDisposer _onMoneroBalanceChangeReaction;