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 bitcoinTransactionPriority = 'current_fee_priority_bitcoin';
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(TransactionsPage(dashboardViewModel: walletViewModel));
if (walletViewModel.shouldShowYatPopup) {
await Future<void>.delayed(Duration(seconds: 1));
await showPopUp<void>(
context: context,
@ -164,6 +165,8 @@ class DashboardPage extends BasePage {
dashboardViewModel: walletViewModel,
onClose: () => Navigator.of(context).pop());
});
walletViewModel.furtherShowYatPopup(false);
}
autorun((_) async {
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:cake_wallet/src/widgets/base_alert_dialog.dart';
@ -22,14 +23,53 @@ class ChooseYatAddressAlert extends BaseAlertDialog {
bool get barrierDismissible => false;
@override
Widget actionButtons(BuildContext context) {
return Container(
Widget actionButtons(BuildContext context) =>
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,
height: 105,
height: 158,
color: Theme.of(context).accentTextTheme.body1.backgroundColor,
child: ListView.separated(
controller: controller,
padding: EdgeInsets.all(0),
itemCount: addresses.length,
itemCount: itemCount,
separatorBuilder: (_, __) => Container(
height: 1,
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});
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
Widget build(BuildContext context) {

View file

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

View file

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

View file

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

View file

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

View file

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