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,7 +43,8 @@ class DashboardPage extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(body: LayoutBuilder(
|
||||
return Scaffold(
|
||||
body: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
if (DeviceInfo.instance.isDesktop) {
|
||||
if (constraints.maxWidth > ResponsiveLayoutUtil.kDesktopMaxDashBoardWidthConstraint) {
|
||||
|
@ -64,9 +65,9 @@ class DashboardPage extends StatelessWidget {
|
|||
} else {
|
||||
return getIt.get<DesktopSidebarWrapper>();
|
||||
}
|
||||
|
||||
},
|
||||
));
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,12 +91,18 @@ class _DashboardPageView extends BasePage {
|
|||
Widget Function(BuildContext, Widget) get rootWrapper =>
|
||||
(BuildContext context, Widget scaffold) => Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(colors: [
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
Theme.of(context).colorScheme.secondary,
|
||||
Theme.of(context).scaffoldBackgroundColor,
|
||||
Theme.of(context).primaryColor,
|
||||
], begin: Alignment.topRight, end: Alignment.bottomLeft)),
|
||||
child: scaffold);
|
||||
],
|
||||
begin: Alignment.topRight,
|
||||
end: Alignment.bottomLeft,
|
||||
),
|
||||
),
|
||||
child: scaffold,
|
||||
);
|
||||
|
||||
@override
|
||||
bool get resizeToAvoidBottomInset => false;
|
||||
|
@ -107,16 +114,16 @@ class _DashboardPageView extends BasePage {
|
|||
Widget middle(BuildContext context) {
|
||||
return SyncIndicator(
|
||||
dashboardViewModel: dashboardViewModel,
|
||||
onTap: () => Navigator.of(context, rootNavigator: true).pushNamed(Routes.connectionSync));
|
||||
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,
|
||||
|
@ -127,8 +134,9 @@ class _DashboardPageView extends BasePage {
|
|||
//splashColor: Colors.transparent,
|
||||
//padding: EdgeInsets.all(0),
|
||||
onPressed: () => onOpenEndDrawer(),
|
||||
child: Semantics(
|
||||
label: S.of(context).wallet_menu, child: menuButton)));
|
||||
child: Semantics(label: S.of(context).wallet_menu, child: menuButton),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final DashboardViewModel dashboardViewModel;
|
||||
|
@ -142,7 +150,9 @@ class _DashboardPageView extends BasePage {
|
|||
Widget body(BuildContext context) {
|
||||
final controller = PageController(initialPage: initialPage);
|
||||
|
||||
reaction((_) => dashboardViewModel.shouldShowMarketPlaceInDashboard, (bool value) {
|
||||
reaction(
|
||||
(_) => dashboardViewModel.shouldShowMarketPlaceInDashboard,
|
||||
(bool value) {
|
||||
if (!dashboardViewModel.shouldShowMarketPlaceInDashboard) {
|
||||
controller.jumpToPage(0);
|
||||
}
|
||||
|
@ -155,7 +165,8 @@ class _DashboardPageView extends BasePage {
|
|||
} else {
|
||||
controller.jumpToPage(0);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
_setEffects(context);
|
||||
|
||||
return SafeArea(
|
||||
|
@ -164,15 +175,20 @@ class _DashboardPageView extends BasePage {
|
|||
mainAxisSize: MainAxisSize.max,
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Observer(builder: (context) {
|
||||
child: Observer(
|
||||
builder: (context) {
|
||||
return PageView.builder(
|
||||
controller: controller,
|
||||
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) {
|
||||
child: Observer(
|
||||
builder: (context) {
|
||||
return ExcludeSemantics(
|
||||
child: SmoothPageIndicator(
|
||||
controller: controller,
|
||||
|
@ -183,15 +199,16 @@ class _DashboardPageView extends BasePage {
|
|||
dotWidth: 6.0,
|
||||
dotHeight: 6.0,
|
||||
dotColor: Theme.of(context).indicatorColor,
|
||||
activeDotColor: Theme.of(context)
|
||||
.accentTextTheme!
|
||||
.headlineMedium!
|
||||
.backgroundColor!),
|
||||
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(
|
||||
.map(
|
||||
(action) => Semantics(
|
||||
button: true,
|
||||
enabled: (action.isEnabled
|
||||
?.call(dashboardViewModel) ??
|
||||
true),
|
||||
enabled: (action.isEnabled?.call(dashboardViewModel) ?? true),
|
||||
child: ActionButton(
|
||||
image: Image.asset(action.image,
|
||||
image: Image.asset(
|
||||
action.image,
|
||||
height: 24,
|
||||
width: 24,
|
||||
color: action.isEnabled?.call(
|
||||
dashboardViewModel) ??
|
||||
true
|
||||
color: action.isEnabled?.call(dashboardViewModel) ?? true
|
||||
? Theme.of(context)
|
||||
.accentTextTheme!
|
||||
.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
|
||||
: 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,12 +289,16 @@ 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 {
|
||||
autorun(
|
||||
(_) async {
|
||||
if (!dashboardViewModel.isOutdatedElectrumWallet) {
|
||||
return;
|
||||
}
|
||||
|
@ -293,36 +312,46 @@ class _DashboardPageView extends BasePage {
|
|||
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) {
|
||||
_onInactiveSub = rootKey.currentState!.isInactive.listen(
|
||||
(inactive) {
|
||||
isInactive = inactive;
|
||||
|
||||
if (needToPresentYat) {
|
||||
Future<void>.delayed(Duration(milliseconds: 500)).then((_) {
|
||||
Future<void>.delayed(Duration(milliseconds: 500)).then(
|
||||
(_) {
|
||||
showPopUp<void>(
|
||||
context: navigatorKey.currentContext!,
|
||||
builder: (_) => YatEmojiId(dashboardViewModel.yatStore.emoji));
|
||||
builder: (_) => YatEmojiId(dashboardViewModel.yatStore.emoji),
|
||||
);
|
||||
needToPresentYat = false;
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
dashboardViewModel.yatStore.emojiIncommingStream.listen((String emoji) {
|
||||
dashboardViewModel.yatStore.emojiIncommingStream.listen(
|
||||
(String emoji) {
|
||||
if (!_isEffectsInstalled || emoji.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
needToPresentYat = true;
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showReleaseNotesPopup(BuildContext context) async {
|
||||
|
@ -333,14 +362,19 @@ class _DashboardPageView extends BasePage {
|
|||
final isNewInstall = sharedPrefs.getBool(PreferencesKey.isNewInstall);
|
||||
|
||||
if (currentAppVersion != lastSeenAppVersion && !isNewInstall!) {
|
||||
Future<void>.delayed(Duration(seconds: 1), () {
|
||||
Future<void>.delayed(
|
||||
Duration(seconds: 1),
|
||||
() {
|
||||
showPopUp<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ReleaseNotesScreen(
|
||||
title: 'Version ${dashboardViewModel.settingsStore.appVersion}');
|
||||
});
|
||||
});
|
||||
title: 'Version ${dashboardViewModel.settingsStore.appVersion}',
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
sharedPrefs.setInt(PreferencesKey.lastSeenAppVersion, currentAppVersion);
|
||||
} else if (isNewInstall!) {
|
||||
|
|
Loading…
Reference in a new issue