feat: Replace buy action to use onramper (#1026)

This commit is contained in:
Adegoke David 2023-08-08 16:09:51 +01:00 committed by GitHub
parent 8185b88b4a
commit fb5a1112e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 199 additions and 171 deletions

View file

@ -47,6 +47,7 @@ class MainActions {
case WalletType.bitcoin: case WalletType.bitcoin:
case WalletType.litecoin: case WalletType.litecoin:
case WalletType.ethereum: case WalletType.ethereum:
case WalletType.monero:
if (viewModel.isEnabledBuyAction) { if (viewModel.isEnabledBuyAction) {
final uri = getIt.get<OnRamperBuyProvider>().requestUrl(); final uri = getIt.get<OnRamperBuyProvider>().requestUrl();
if (DeviceInfo.instance.isMobile) { if (DeviceInfo.instance.isMobile) {
@ -57,13 +58,6 @@ class MainActions {
} }
} }
break; break;
case WalletType.monero:
if (viewModel.isEnabledBuyAction) {
// final uri = getIt.get<PayfuraBuyProvider>().requestUrl();
final uri = Uri.parse("https://monero.com/trade");
await launchUrl(uri);
}
break;
default: default:
await showPopUp<void>( await showPopUp<void>(
context: context, context: context,

View file

@ -43,30 +43,31 @@ class DashboardPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold(body: LayoutBuilder( return Scaffold(
builder: (context, constraints) { body: LayoutBuilder(
if (DeviceInfo.instance.isDesktop) { builder: (context, constraints) {
if (constraints.maxWidth > ResponsiveLayoutUtil.kDesktopMaxDashBoardWidthConstraint) { if (DeviceInfo.instance.isDesktop) {
return getIt.get<DesktopSidebarWrapper>(); if (constraints.maxWidth > ResponsiveLayoutUtil.kDesktopMaxDashBoardWidthConstraint) {
} else { return getIt.get<DesktopSidebarWrapper>();
} else {
return _DashboardPageView(
balancePage: balancePage,
dashboardViewModel: dashboardViewModel,
addressListViewModel: addressListViewModel,
);
}
} else if (ResponsiveLayoutUtil.instance.shouldRenderMobileUI()) {
return _DashboardPageView( return _DashboardPageView(
balancePage: balancePage, balancePage: balancePage,
dashboardViewModel: dashboardViewModel, dashboardViewModel: dashboardViewModel,
addressListViewModel: addressListViewModel, addressListViewModel: addressListViewModel,
); );
} else {
return getIt.get<DesktopSidebarWrapper>();
} }
} else if (ResponsiveLayoutUtil.instance.shouldRenderMobileUI()) { },
return _DashboardPageView( ),
balancePage: balancePage, );
dashboardViewModel: dashboardViewModel,
addressListViewModel: addressListViewModel,
);
} else {
return getIt.get<DesktopSidebarWrapper>();
}
},
));
} }
} }
@ -89,13 +90,19 @@ class _DashboardPageView extends BasePage {
@override @override
Widget Function(BuildContext, Widget) get rootWrapper => Widget Function(BuildContext, Widget) get rootWrapper =>
(BuildContext context, Widget scaffold) => Container( (BuildContext context, Widget scaffold) => Container(
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: LinearGradient(colors: [ gradient: LinearGradient(
Theme.of(context).colorScheme.secondary, colors: [
Theme.of(context).scaffoldBackgroundColor, Theme.of(context).colorScheme.secondary,
Theme.of(context).primaryColor, Theme.of(context).scaffoldBackgroundColor,
], begin: Alignment.topRight, end: Alignment.bottomLeft)), Theme.of(context).primaryColor,
child: scaffold); ],
begin: Alignment.topRight,
end: Alignment.bottomLeft,
),
),
child: scaffold,
);
@override @override
bool get resizeToAvoidBottomInset => false; bool get resizeToAvoidBottomInset => false;
@ -106,29 +113,30 @@ class _DashboardPageView extends BasePage {
@override @override
Widget middle(BuildContext context) { Widget middle(BuildContext context) {
return SyncIndicator( return SyncIndicator(
dashboardViewModel: dashboardViewModel, dashboardViewModel: dashboardViewModel,
onTap: () => Navigator.of(context, rootNavigator: true).pushNamed(Routes.connectionSync)); onTap: () => Navigator.of(context, rootNavigator: true).pushNamed(Routes.connectionSync),
);
} }
@override @override
Widget trailing(BuildContext context) { Widget trailing(BuildContext context) {
final menuButton = Image.asset('assets/images/menu.png', final menuButton = Image.asset(
color: Theme.of(context) 'assets/images/menu.png',
.accentTextTheme! color: Theme.of(context).accentTextTheme.displayMedium!.backgroundColor,
.displayMedium! );
.backgroundColor);
return Container( return Container(
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
width: 40, width: 40,
child: TextButton( child: TextButton(
// FIX-ME: Style // FIX-ME: Style
//highlightColor: Colors.transparent, //highlightColor: Colors.transparent,
//splashColor: Colors.transparent, //splashColor: Colors.transparent,
//padding: EdgeInsets.all(0), //padding: EdgeInsets.all(0),
onPressed: () => onOpenEndDrawer(), onPressed: () => onOpenEndDrawer(),
child: Semantics( child: Semantics(label: S.of(context).wallet_menu, child: menuButton),
label: S.of(context).wallet_menu, child: menuButton))); ),
);
} }
final DashboardViewModel dashboardViewModel; final DashboardViewModel dashboardViewModel;
@ -142,56 +150,65 @@ class _DashboardPageView extends BasePage {
Widget body(BuildContext context) { Widget body(BuildContext context) {
final controller = PageController(initialPage: initialPage); final controller = PageController(initialPage: initialPage);
reaction((_) => dashboardViewModel.shouldShowMarketPlaceInDashboard, (bool value) { reaction(
if (!dashboardViewModel.shouldShowMarketPlaceInDashboard) { (_) => dashboardViewModel.shouldShowMarketPlaceInDashboard,
controller.jumpToPage(0); (bool value) {
} if (!dashboardViewModel.shouldShowMarketPlaceInDashboard) {
pages.clear(); controller.jumpToPage(0);
_isEffectsInstalled = false; }
_setEffects(context); pages.clear();
_isEffectsInstalled = false;
_setEffects(context);
if (value) { if (value) {
controller.jumpToPage(1); controller.jumpToPage(1);
} else { } else {
controller.jumpToPage(0); controller.jumpToPage(0);
} }
}); },
);
_setEffects(context); _setEffects(context);
return SafeArea( return SafeArea(
minimum: EdgeInsets.only(bottom: 24), minimum: EdgeInsets.only(bottom: 24),
child: Column( child: Column(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: Observer(builder: (context) { child: Observer(
return PageView.builder( builder: (context) {
return PageView.builder(
controller: controller, controller: controller,
itemCount: pages.length, itemCount: pages.length,
itemBuilder: (context, index) => pages[index]); itemBuilder: (context, index) => pages[index],
})), );
Padding( },
padding: EdgeInsets.only(bottom: 24, top: 10), ),
child: Observer(builder: (context) { ),
return ExcludeSemantics( Padding(
child: SmoothPageIndicator( padding: EdgeInsets.only(bottom: 24, top: 10),
controller: controller, child: Observer(
count: pages.length, builder: (context) {
effect: ColorTransitionEffect( return ExcludeSemantics(
spacing: 6.0, child: SmoothPageIndicator(
radius: 6.0, controller: controller,
dotWidth: 6.0, count: pages.length,
dotHeight: 6.0, effect: ColorTransitionEffect(
dotColor: Theme.of(context).indicatorColor, spacing: 6.0,
activeDotColor: Theme.of(context) radius: 6.0,
.accentTextTheme! dotWidth: 6.0,
.headlineMedium! dotHeight: 6.0,
.backgroundColor!), dotColor: Theme.of(context).indicatorColor,
activeDotColor:
Theme.of(context).accentTextTheme.headlineMedium!.backgroundColor!,
), ),
); ),
} );
)), },
Observer(builder: (_) { ),
),
Observer(
builder: (_) {
return ClipRect( return ClipRect(
child: Container( child: Container(
margin: const EdgeInsets.only(left: 16, right: 16), margin: const EdgeInsets.only(left: 16, right: 16),
@ -204,10 +221,7 @@ class _DashboardPageView extends BasePage {
: Colors.transparent, : Colors.transparent,
width: 1, width: 1,
), ),
color: Theme.of(context) color: Theme.of(context).textTheme.titleLarge!.backgroundColor!,
.textTheme!
.titleLarge!
.backgroundColor!,
), ),
child: Container( child: Container(
padding: EdgeInsets.only(left: 32, right: 32), padding: EdgeInsets.only(left: 32, right: 32),
@ -215,48 +229,48 @@ class _DashboardPageView extends BasePage {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: MainActions.all children: MainActions.all
.where((element) => element.canShow?.call(dashboardViewModel) ?? true) .where((element) => element.canShow?.call(dashboardViewModel) ?? true)
.map((action) => Semantics( .map(
button: true, (action) => Semantics(
enabled: (action.isEnabled button: true,
?.call(dashboardViewModel) ?? enabled: (action.isEnabled?.call(dashboardViewModel) ?? true),
true), child: ActionButton(
child: ActionButton( image: Image.asset(
image: Image.asset(action.image, action.image,
height: 24, height: 24,
width: 24, width: 24,
color: action.isEnabled?.call( color: action.isEnabled?.call(dashboardViewModel) ?? true
dashboardViewModel) ?? ? Theme.of(context)
true .accentTextTheme
? Theme.of(context) .displayMedium!
.accentTextTheme! .backgroundColor!
.displayMedium!
.backgroundColor!
: Theme.of(context)
.accentTextTheme!
.displaySmall!
.backgroundColor!),
title: action.name(context),
onClick: () async => await action.onTap(
context, dashboardViewModel),
textColor: action.isEnabled
?.call(dashboardViewModel) ??
true
? null
: Theme.of(context) : Theme.of(context)
.accentTextTheme! .accentTextTheme
.displaySmall! .displaySmall!
.backgroundColor!, .backgroundColor!,
), ),
)) title: action.name(context),
onClick: () async =>
await action.onTap(context, dashboardViewModel),
textColor: action.isEnabled?.call(dashboardViewModel) ?? true
? null
: Theme.of(context)
.accentTextTheme
.displaySmall!
.backgroundColor!,
),
),
)
.toList(), .toList(),
), ),
), ),
), ),
), ),
); );
}), },
], ),
)); ],
),
);
} }
void _setEffects(BuildContext context) async { void _setEffects(BuildContext context) async {
@ -264,7 +278,8 @@ class _DashboardPageView extends BasePage {
return; return;
} }
if (dashboardViewModel.shouldShowMarketPlaceInDashboard) { if (dashboardViewModel.shouldShowMarketPlaceInDashboard) {
pages.add(Semantics( pages.add(
Semantics(
label: S.of(context).market_place, label: S.of(context).market_place,
child: MarketPlacePage( child: MarketPlacePage(
dashboardViewModel: dashboardViewModel, dashboardViewModel: dashboardViewModel,
@ -274,73 +289,92 @@ class _DashboardPageView extends BasePage {
); );
} }
pages.add(Semantics(label: S.of(context).balance_page, child: balancePage)); pages.add(Semantics(label: S.of(context).balance_page, child: balancePage));
pages.add(Semantics( pages.add(
Semantics(
label: S.of(context).settings_transactions, label: S.of(context).settings_transactions,
child: TransactionsPage(dashboardViewModel: dashboardViewModel))); child: TransactionsPage(dashboardViewModel: dashboardViewModel),
),
);
_isEffectsInstalled = true; _isEffectsInstalled = true;
autorun((_) async { autorun(
if (!dashboardViewModel.isOutdatedElectrumWallet) { (_) async {
return; if (!dashboardViewModel.isOutdatedElectrumWallet) {
} return;
}
await Future<void>.delayed(Duration(seconds: 1)); await Future<void>.delayed(Duration(seconds: 1));
if (context.mounted) { if (context.mounted) {
await showPopUp<void>( await showPopUp<void>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertWithOneAction( return AlertWithOneAction(
alertTitle: S.of(context).pre_seed_title, alertTitle: S.of(context).pre_seed_title,
alertContent: S.of(context).outdated_electrum_wallet_description, alertContent: S.of(context).outdated_electrum_wallet_description,
buttonText: S.of(context).understand, buttonText: S.of(context).understand,
buttonAction: () => Navigator.of(context).pop()); buttonAction: () => Navigator.of(context).pop(),
}); );
} },
}); );
}
},
);
_showReleaseNotesPopup(context); _showReleaseNotesPopup(context);
var needToPresentYat = false; var needToPresentYat = false;
var isInactive = false; var isInactive = false;
_onInactiveSub = rootKey.currentState!.isInactive.listen((inactive) { _onInactiveSub = rootKey.currentState!.isInactive.listen(
isInactive = inactive; (inactive) {
isInactive = inactive;
if (needToPresentYat) { if (needToPresentYat) {
Future<void>.delayed(Duration(milliseconds: 500)).then((_) { Future<void>.delayed(Duration(milliseconds: 500)).then(
showPopUp<void>( (_) {
context: navigatorKey.currentContext!, showPopUp<void>(
builder: (_) => YatEmojiId(dashboardViewModel.yatStore.emoji)); context: navigatorKey.currentContext!,
needToPresentYat = false; builder: (_) => YatEmojiId(dashboardViewModel.yatStore.emoji),
}); );
} needToPresentYat = false;
}); },
);
}
},
);
dashboardViewModel.yatStore.emojiIncommingStream.listen((String emoji) { dashboardViewModel.yatStore.emojiIncommingStream.listen(
if (!_isEffectsInstalled || emoji.isEmpty) { (String emoji) {
return; if (!_isEffectsInstalled || emoji.isEmpty) {
} return;
}
needToPresentYat = true; needToPresentYat = true;
}); },
);
} }
void _showReleaseNotesPopup(BuildContext context) async { void _showReleaseNotesPopup(BuildContext context) async {
final sharedPrefs = await SharedPreferences.getInstance(); final sharedPrefs = await SharedPreferences.getInstance();
final currentAppVersion = final currentAppVersion =
VersionComparator.getExtendedVersionNumber(dashboardViewModel.settingsStore.appVersion); VersionComparator.getExtendedVersionNumber(dashboardViewModel.settingsStore.appVersion);
final lastSeenAppVersion = sharedPrefs.getInt(PreferencesKey.lastSeenAppVersion); final lastSeenAppVersion = sharedPrefs.getInt(PreferencesKey.lastSeenAppVersion);
final isNewInstall = sharedPrefs.getBool(PreferencesKey.isNewInstall); final isNewInstall = sharedPrefs.getBool(PreferencesKey.isNewInstall);
if (currentAppVersion != lastSeenAppVersion && !isNewInstall!) { if (currentAppVersion != lastSeenAppVersion && !isNewInstall!) {
Future<void>.delayed(Duration(seconds: 1), () { Future<void>.delayed(
showPopUp<void>( Duration(seconds: 1),
context: context, () {
builder: (BuildContext context) { showPopUp<void>(
return ReleaseNotesScreen( context: context,
title: 'Version ${dashboardViewModel.settingsStore.appVersion}'); builder: (BuildContext context) {
}); return ReleaseNotesScreen(
}); title: 'Version ${dashboardViewModel.settingsStore.appVersion}',
);
},
);
},
);
sharedPrefs.setInt(PreferencesKey.lastSeenAppVersion, currentAppVersion); sharedPrefs.setInt(PreferencesKey.lastSeenAppVersion, currentAppVersion);
} else if (isNewInstall!) { } else if (isNewInstall!) {