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,7 +43,8 @@ class DashboardPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold(body: LayoutBuilder( return Scaffold(
body: LayoutBuilder(
builder: (context, constraints) { builder: (context, constraints) {
if (DeviceInfo.instance.isDesktop) { if (DeviceInfo.instance.isDesktop) {
if (constraints.maxWidth > ResponsiveLayoutUtil.kDesktopMaxDashBoardWidthConstraint) { if (constraints.maxWidth > ResponsiveLayoutUtil.kDesktopMaxDashBoardWidthConstraint) {
@ -64,9 +65,9 @@ class DashboardPage extends StatelessWidget {
} else { } else {
return getIt.get<DesktopSidebarWrapper>(); return getIt.get<DesktopSidebarWrapper>();
} }
}, },
)); ),
);
} }
} }
@ -90,12 +91,18 @@ class _DashboardPageView extends BasePage {
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(
colors: [
Theme.of(context).colorScheme.secondary, Theme.of(context).colorScheme.secondary,
Theme.of(context).scaffoldBackgroundColor, Theme.of(context).scaffoldBackgroundColor,
Theme.of(context).primaryColor, Theme.of(context).primaryColor,
], begin: Alignment.topRight, end: Alignment.bottomLeft)), ],
child: scaffold); begin: Alignment.topRight,
end: Alignment.bottomLeft,
),
),
child: scaffold,
);
@override @override
bool get resizeToAvoidBottomInset => false; bool get resizeToAvoidBottomInset => false;
@ -107,16 +114,16 @@ class _DashboardPageView extends BasePage {
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,
@ -127,8 +134,9 @@ class _DashboardPageView extends BasePage {
//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,7 +150,9 @@ 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(
(_) => dashboardViewModel.shouldShowMarketPlaceInDashboard,
(bool value) {
if (!dashboardViewModel.shouldShowMarketPlaceInDashboard) { if (!dashboardViewModel.shouldShowMarketPlaceInDashboard) {
controller.jumpToPage(0); controller.jumpToPage(0);
} }
@ -155,7 +165,8 @@ class _DashboardPageView extends BasePage {
} else { } else {
controller.jumpToPage(0); controller.jumpToPage(0);
} }
}); },
);
_setEffects(context); _setEffects(context);
return SafeArea( return SafeArea(
@ -164,15 +175,20 @@ class _DashboardPageView extends BasePage {
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: Observer(builder: (context) { child: Observer(
builder: (context) {
return PageView.builder( 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(
padding: EdgeInsets.only(bottom: 24, top: 10), padding: EdgeInsets.only(bottom: 24, top: 10),
child: Observer(builder: (context) { child: Observer(
builder: (context) {
return ExcludeSemantics( return ExcludeSemantics(
child: SmoothPageIndicator( child: SmoothPageIndicator(
controller: controller, controller: controller,
@ -183,15 +199,16 @@ class _DashboardPageView extends BasePage {
dotWidth: 6.0, dotWidth: 6.0,
dotHeight: 6.0, dotHeight: 6.0,
dotColor: Theme.of(context).indicatorColor, dotColor: Theme.of(context).indicatorColor,
activeDotColor: Theme.of(context) activeDotColor:
.accentTextTheme! Theme.of(context).accentTextTheme.headlineMedium!.backgroundColor!,
.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(
(action) => Semantics(
button: true, button: true,
enabled: (action.isEnabled enabled: (action.isEnabled?.call(dashboardViewModel) ?? true),
?.call(dashboardViewModel) ??
true),
child: ActionButton( child: ActionButton(
image: Image.asset(action.image, image: Image.asset(
action.image,
height: 24, height: 24,
width: 24, width: 24,
color: action.isEnabled?.call( color: action.isEnabled?.call(dashboardViewModel) ?? true
dashboardViewModel) ??
true
? Theme.of(context) ? Theme.of(context)
.accentTextTheme! .accentTextTheme
.displayMedium! .displayMedium!
.backgroundColor! .backgroundColor!
: Theme.of(context) : Theme.of(context)
.accentTextTheme! .accentTextTheme
.displaySmall!
.backgroundColor!),
title: action.name(context),
onClick: () async => await action.onTap(
context, dashboardViewModel),
textColor: action.isEnabled
?.call(dashboardViewModel) ??
true
? null
: Theme.of(context)
.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,12 +289,16 @@ 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(
(_) async {
if (!dashboardViewModel.isOutdatedElectrumWallet) { if (!dashboardViewModel.isOutdatedElectrumWallet) {
return; return;
} }
@ -293,36 +312,46 @@ class _DashboardPageView extends BasePage {
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(
(inactive) {
isInactive = inactive; isInactive = inactive;
if (needToPresentYat) { if (needToPresentYat) {
Future<void>.delayed(Duration(milliseconds: 500)).then((_) { Future<void>.delayed(Duration(milliseconds: 500)).then(
(_) {
showPopUp<void>( showPopUp<void>(
context: navigatorKey.currentContext!, context: navigatorKey.currentContext!,
builder: (_) => YatEmojiId(dashboardViewModel.yatStore.emoji)); builder: (_) => YatEmojiId(dashboardViewModel.yatStore.emoji),
);
needToPresentYat = false; needToPresentYat = false;
}); },
);
} }
}); },
);
dashboardViewModel.yatStore.emojiIncommingStream.listen((String emoji) { dashboardViewModel.yatStore.emojiIncommingStream.listen(
(String emoji) {
if (!_isEffectsInstalled || emoji.isEmpty) { if (!_isEffectsInstalled || emoji.isEmpty) {
return; return;
} }
needToPresentYat = true; needToPresentYat = true;
}); },
);
} }
void _showReleaseNotesPopup(BuildContext context) async { void _showReleaseNotesPopup(BuildContext context) async {
@ -333,14 +362,19 @@ class _DashboardPageView extends BasePage {
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(
Duration(seconds: 1),
() {
showPopUp<void>( showPopUp<void>(
context: context, context: context,
builder: (BuildContext context) { builder: (BuildContext context) {
return ReleaseNotesScreen( return ReleaseNotesScreen(
title: 'Version ${dashboardViewModel.settingsStore.appVersion}'); title: 'Version ${dashboardViewModel.settingsStore.appVersion}',
}); );
}); },
);
},
);
sharedPrefs.setInt(PreferencesKey.lastSeenAppVersion, currentAppVersion); sharedPrefs.setInt(PreferencesKey.lastSeenAppVersion, currentAppVersion);
} else if (isNewInstall!) { } else if (isNewInstall!) {