mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
feat: Replace buy action to use onramper (#1026)
This commit is contained in:
parent
8185b88b4a
commit
fb5a1112e2
2 changed files with 199 additions and 171 deletions
|
@ -47,6 +47,7 @@ class MainActions {
|
|||
case WalletType.bitcoin:
|
||||
case WalletType.litecoin:
|
||||
case WalletType.ethereum:
|
||||
case WalletType.monero:
|
||||
if (viewModel.isEnabledBuyAction) {
|
||||
final uri = getIt.get<OnRamperBuyProvider>().requestUrl();
|
||||
if (DeviceInfo.instance.isMobile) {
|
||||
|
@ -57,13 +58,6 @@ class MainActions {
|
|||
}
|
||||
}
|
||||
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:
|
||||
await showPopUp<void>(
|
||||
context: context,
|
||||
|
|
|
@ -43,30 +43,31 @@ class DashboardPage extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(body: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
if (DeviceInfo.instance.isDesktop) {
|
||||
if (constraints.maxWidth > ResponsiveLayoutUtil.kDesktopMaxDashBoardWidthConstraint) {
|
||||
return getIt.get<DesktopSidebarWrapper>();
|
||||
} else {
|
||||
return Scaffold(
|
||||
body: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
if (DeviceInfo.instance.isDesktop) {
|
||||
if (constraints.maxWidth > ResponsiveLayoutUtil.kDesktopMaxDashBoardWidthConstraint) {
|
||||
return getIt.get<DesktopSidebarWrapper>();
|
||||
} else {
|
||||
return _DashboardPageView(
|
||||
balancePage: balancePage,
|
||||
dashboardViewModel: dashboardViewModel,
|
||||
addressListViewModel: addressListViewModel,
|
||||
);
|
||||
}
|
||||
} else if (ResponsiveLayoutUtil.instance.shouldRenderMobileUI()) {
|
||||
return _DashboardPageView(
|
||||
balancePage: balancePage,
|
||||
dashboardViewModel: dashboardViewModel,
|
||||
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
|
||||
Widget Function(BuildContext, Widget) get rootWrapper =>
|
||||
(BuildContext context, Widget scaffold) => Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(colors: [
|
||||
Theme.of(context).colorScheme.secondary,
|
||||
Theme.of(context).scaffoldBackgroundColor,
|
||||
Theme.of(context).primaryColor,
|
||||
], begin: Alignment.topRight, end: Alignment.bottomLeft)),
|
||||
child: scaffold);
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
Theme.of(context).colorScheme.secondary,
|
||||
Theme.of(context).scaffoldBackgroundColor,
|
||||
Theme.of(context).primaryColor,
|
||||
],
|
||||
begin: Alignment.topRight,
|
||||
end: Alignment.bottomLeft,
|
||||
),
|
||||
),
|
||||
child: scaffold,
|
||||
);
|
||||
|
||||
@override
|
||||
bool get resizeToAvoidBottomInset => false;
|
||||
|
@ -106,29 +113,30 @@ class _DashboardPageView extends BasePage {
|
|||
@override
|
||||
Widget middle(BuildContext context) {
|
||||
return SyncIndicator(
|
||||
dashboardViewModel: dashboardViewModel,
|
||||
onTap: () => Navigator.of(context, rootNavigator: true).pushNamed(Routes.connectionSync));
|
||||
dashboardViewModel: dashboardViewModel,
|
||||
onTap: () => Navigator.of(context, rootNavigator: true).pushNamed(Routes.connectionSync),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget trailing(BuildContext context) {
|
||||
final menuButton = Image.asset('assets/images/menu.png',
|
||||
color: Theme.of(context)
|
||||
.accentTextTheme!
|
||||
.displayMedium!
|
||||
.backgroundColor);
|
||||
final menuButton = Image.asset(
|
||||
'assets/images/menu.png',
|
||||
color: Theme.of(context).accentTextTheme.displayMedium!.backgroundColor,
|
||||
);
|
||||
|
||||
return Container(
|
||||
alignment: Alignment.centerRight,
|
||||
width: 40,
|
||||
child: TextButton(
|
||||
// FIX-ME: Style
|
||||
//highlightColor: Colors.transparent,
|
||||
//splashColor: Colors.transparent,
|
||||
//padding: EdgeInsets.all(0),
|
||||
onPressed: () => onOpenEndDrawer(),
|
||||
child: Semantics(
|
||||
label: S.of(context).wallet_menu, child: menuButton)));
|
||||
alignment: Alignment.centerRight,
|
||||
width: 40,
|
||||
child: TextButton(
|
||||
// FIX-ME: Style
|
||||
//highlightColor: Colors.transparent,
|
||||
//splashColor: Colors.transparent,
|
||||
//padding: EdgeInsets.all(0),
|
||||
onPressed: () => onOpenEndDrawer(),
|
||||
child: Semantics(label: S.of(context).wallet_menu, child: menuButton),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final DashboardViewModel dashboardViewModel;
|
||||
|
@ -142,56 +150,65 @@ class _DashboardPageView extends BasePage {
|
|||
Widget body(BuildContext context) {
|
||||
final controller = PageController(initialPage: initialPage);
|
||||
|
||||
reaction((_) => dashboardViewModel.shouldShowMarketPlaceInDashboard, (bool value) {
|
||||
if (!dashboardViewModel.shouldShowMarketPlaceInDashboard) {
|
||||
controller.jumpToPage(0);
|
||||
}
|
||||
pages.clear();
|
||||
_isEffectsInstalled = false;
|
||||
_setEffects(context);
|
||||
reaction(
|
||||
(_) => dashboardViewModel.shouldShowMarketPlaceInDashboard,
|
||||
(bool value) {
|
||||
if (!dashboardViewModel.shouldShowMarketPlaceInDashboard) {
|
||||
controller.jumpToPage(0);
|
||||
}
|
||||
pages.clear();
|
||||
_isEffectsInstalled = false;
|
||||
_setEffects(context);
|
||||
|
||||
if (value) {
|
||||
controller.jumpToPage(1);
|
||||
} else {
|
||||
controller.jumpToPage(0);
|
||||
}
|
||||
});
|
||||
if (value) {
|
||||
controller.jumpToPage(1);
|
||||
} else {
|
||||
controller.jumpToPage(0);
|
||||
}
|
||||
},
|
||||
);
|
||||
_setEffects(context);
|
||||
|
||||
return SafeArea(
|
||||
minimum: EdgeInsets.only(bottom: 24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Observer(builder: (context) {
|
||||
return PageView.builder(
|
||||
minimum: EdgeInsets.only(bottom: 24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Observer(
|
||||
builder: (context) {
|
||||
return PageView.builder(
|
||||
controller: controller,
|
||||
itemCount: pages.length,
|
||||
itemBuilder: (context, index) => pages[index]);
|
||||
})),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(bottom: 24, top: 10),
|
||||
child: Observer(builder: (context) {
|
||||
return ExcludeSemantics(
|
||||
child: SmoothPageIndicator(
|
||||
controller: controller,
|
||||
count: pages.length,
|
||||
effect: ColorTransitionEffect(
|
||||
spacing: 6.0,
|
||||
radius: 6.0,
|
||||
dotWidth: 6.0,
|
||||
dotHeight: 6.0,
|
||||
dotColor: Theme.of(context).indicatorColor,
|
||||
activeDotColor: Theme.of(context)
|
||||
.accentTextTheme!
|
||||
.headlineMedium!
|
||||
.backgroundColor!),
|
||||
itemBuilder: (context, index) => pages[index],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(bottom: 24, top: 10),
|
||||
child: Observer(
|
||||
builder: (context) {
|
||||
return ExcludeSemantics(
|
||||
child: SmoothPageIndicator(
|
||||
controller: controller,
|
||||
count: pages.length,
|
||||
effect: ColorTransitionEffect(
|
||||
spacing: 6.0,
|
||||
radius: 6.0,
|
||||
dotWidth: 6.0,
|
||||
dotHeight: 6.0,
|
||||
dotColor: Theme.of(context).indicatorColor,
|
||||
activeDotColor:
|
||||
Theme.of(context).accentTextTheme.headlineMedium!.backgroundColor!,
|
||||
),
|
||||
);
|
||||
}
|
||||
)),
|
||||
Observer(builder: (_) {
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Observer(
|
||||
builder: (_) {
|
||||
return ClipRect(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(left: 16, right: 16),
|
||||
|
@ -204,10 +221,7 @@ class _DashboardPageView extends BasePage {
|
|||
: Colors.transparent,
|
||||
width: 1,
|
||||
),
|
||||
color: Theme.of(context)
|
||||
.textTheme!
|
||||
.titleLarge!
|
||||
.backgroundColor!,
|
||||
color: Theme.of(context).textTheme.titleLarge!.backgroundColor!,
|
||||
),
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(left: 32, right: 32),
|
||||
|
@ -215,48 +229,48 @@ class _DashboardPageView extends BasePage {
|
|||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: MainActions.all
|
||||
.where((element) => element.canShow?.call(dashboardViewModel) ?? true)
|
||||
.map((action) => Semantics(
|
||||
button: true,
|
||||
enabled: (action.isEnabled
|
||||
?.call(dashboardViewModel) ??
|
||||
true),
|
||||
child: ActionButton(
|
||||
image: Image.asset(action.image,
|
||||
height: 24,
|
||||
width: 24,
|
||||
color: action.isEnabled?.call(
|
||||
dashboardViewModel) ??
|
||||
true
|
||||
? Theme.of(context)
|
||||
.accentTextTheme!
|
||||
.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
|
||||
.map(
|
||||
(action) => Semantics(
|
||||
button: true,
|
||||
enabled: (action.isEnabled?.call(dashboardViewModel) ?? true),
|
||||
child: ActionButton(
|
||||
image: Image.asset(
|
||||
action.image,
|
||||
height: 24,
|
||||
width: 24,
|
||||
color: action.isEnabled?.call(dashboardViewModel) ?? true
|
||||
? Theme.of(context)
|
||||
.accentTextTheme
|
||||
.displayMedium!
|
||||
.backgroundColor!
|
||||
: 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!
|
||||
.backgroundColor!,
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _setEffects(BuildContext context) async {
|
||||
|
@ -264,7 +278,8 @@ class _DashboardPageView extends BasePage {
|
|||
return;
|
||||
}
|
||||
if (dashboardViewModel.shouldShowMarketPlaceInDashboard) {
|
||||
pages.add(Semantics(
|
||||
pages.add(
|
||||
Semantics(
|
||||
label: S.of(context).market_place,
|
||||
child: MarketPlacePage(
|
||||
dashboardViewModel: dashboardViewModel,
|
||||
|
@ -274,73 +289,92 @@ class _DashboardPageView extends BasePage {
|
|||
);
|
||||
}
|
||||
pages.add(Semantics(label: S.of(context).balance_page, child: balancePage));
|
||||
pages.add(Semantics(
|
||||
pages.add(
|
||||
Semantics(
|
||||
label: S.of(context).settings_transactions,
|
||||
child: TransactionsPage(dashboardViewModel: dashboardViewModel)));
|
||||
child: TransactionsPage(dashboardViewModel: dashboardViewModel),
|
||||
),
|
||||
);
|
||||
_isEffectsInstalled = true;
|
||||
|
||||
autorun((_) async {
|
||||
if (!dashboardViewModel.isOutdatedElectrumWallet) {
|
||||
return;
|
||||
}
|
||||
autorun(
|
||||
(_) async {
|
||||
if (!dashboardViewModel.isOutdatedElectrumWallet) {
|
||||
return;
|
||||
}
|
||||
|
||||
await Future<void>.delayed(Duration(seconds: 1));
|
||||
if (context.mounted) {
|
||||
await showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
await Future<void>.delayed(Duration(seconds: 1));
|
||||
if (context.mounted) {
|
||||
await showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertWithOneAction(
|
||||
alertTitle: S.of(context).pre_seed_title,
|
||||
alertContent: S.of(context).outdated_electrum_wallet_description,
|
||||
buttonText: S.of(context).understand,
|
||||
buttonAction: () => Navigator.of(context).pop());
|
||||
});
|
||||
}
|
||||
});
|
||||
buttonAction: () => Navigator.of(context).pop(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
_showReleaseNotesPopup(context);
|
||||
|
||||
var needToPresentYat = false;
|
||||
var isInactive = false;
|
||||
|
||||
_onInactiveSub = rootKey.currentState!.isInactive.listen((inactive) {
|
||||
isInactive = inactive;
|
||||
_onInactiveSub = rootKey.currentState!.isInactive.listen(
|
||||
(inactive) {
|
||||
isInactive = inactive;
|
||||
|
||||
if (needToPresentYat) {
|
||||
Future<void>.delayed(Duration(milliseconds: 500)).then((_) {
|
||||
showPopUp<void>(
|
||||
context: navigatorKey.currentContext!,
|
||||
builder: (_) => YatEmojiId(dashboardViewModel.yatStore.emoji));
|
||||
needToPresentYat = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
if (needToPresentYat) {
|
||||
Future<void>.delayed(Duration(milliseconds: 500)).then(
|
||||
(_) {
|
||||
showPopUp<void>(
|
||||
context: navigatorKey.currentContext!,
|
||||
builder: (_) => YatEmojiId(dashboardViewModel.yatStore.emoji),
|
||||
);
|
||||
needToPresentYat = false;
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
dashboardViewModel.yatStore.emojiIncommingStream.listen((String emoji) {
|
||||
if (!_isEffectsInstalled || emoji.isEmpty) {
|
||||
return;
|
||||
}
|
||||
dashboardViewModel.yatStore.emojiIncommingStream.listen(
|
||||
(String emoji) {
|
||||
if (!_isEffectsInstalled || emoji.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
needToPresentYat = true;
|
||||
});
|
||||
needToPresentYat = true;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showReleaseNotesPopup(BuildContext context) async {
|
||||
final sharedPrefs = await SharedPreferences.getInstance();
|
||||
final currentAppVersion =
|
||||
VersionComparator.getExtendedVersionNumber(dashboardViewModel.settingsStore.appVersion);
|
||||
VersionComparator.getExtendedVersionNumber(dashboardViewModel.settingsStore.appVersion);
|
||||
final lastSeenAppVersion = sharedPrefs.getInt(PreferencesKey.lastSeenAppVersion);
|
||||
final isNewInstall = sharedPrefs.getBool(PreferencesKey.isNewInstall);
|
||||
|
||||
if (currentAppVersion != lastSeenAppVersion && !isNewInstall!) {
|
||||
Future<void>.delayed(Duration(seconds: 1), () {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ReleaseNotesScreen(
|
||||
title: 'Version ${dashboardViewModel.settingsStore.appVersion}');
|
||||
});
|
||||
});
|
||||
Future<void>.delayed(
|
||||
Duration(seconds: 1),
|
||||
() {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ReleaseNotesScreen(
|
||||
title: 'Version ${dashboardViewModel.settingsStore.appVersion}',
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
sharedPrefs.setInt(PreferencesKey.lastSeenAppVersion, currentAppVersion);
|
||||
} else if (isNewInstall!) {
|
||||
|
|
Loading…
Reference in a new issue