-
Notifications
You must be signed in to change notification settings - Fork 12
feat: creator token is live dialog #3008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2267a96
feat: UI ready
ice-damocles f14f120
feat: add subscription
ice-damocles 7316bbb
feat: for review
ice-damocles aaff069
chore: PR fixes
ice-damocles 726acc6
fix: PR fixes
ice-damocles 4c19bbd
chore: pattern matching
ice-damocles 407cbac
fix: pass reference to dialog, skip bsc check
ice-damocles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
lib/app/features/tokenized_communities/providers/community_token_definition_handler.r.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // SPDX-License-Identifier: ice License 1.0 | ||
|
|
||
| import 'dart:async'; | ||
|
|
||
| import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
| import 'package:ion/app/features/auth/providers/auth_provider.m.dart'; | ||
| import 'package:ion/app/features/ion_connect/ion_connect.dart'; | ||
| import 'package:ion/app/features/ion_connect/model/event_reference.f.dart'; | ||
| import 'package:ion/app/features/ion_connect/model/global_subscription_event_handler.dart'; | ||
| import 'package:ion/app/features/ion_connect/providers/ion_connect_cache.r.dart'; | ||
| import 'package:ion/app/features/tokenized_communities/models/entities/community_token_definition.f.dart'; | ||
| import 'package:ion/app/features/tokenized_communities/views/creator_token_is_live_dialog.dart'; | ||
| import 'package:ion/app/features/user/model/user_metadata.f.dart'; | ||
| import 'package:ion/app/services/storage/local_storage.r.dart'; | ||
| import 'package:ion/app/services/ui_event_queue/ui_event_queue_notifier.r.dart'; | ||
| import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
|
||
| part 'community_token_definition_handler.r.g.dart'; | ||
|
|
||
| class CommunityTokenDefinitionHandler extends GlobalSubscriptionEventHandler { | ||
| CommunityTokenDefinitionHandler({ | ||
| required this.localStorage, | ||
| required this.ionConnectCache, | ||
| required this.uiEventQueueCallback, | ||
| required this.currentUserMasterPubkey, | ||
| }); | ||
|
|
||
| final LocalStorage localStorage; | ||
| final IonConnectCache ionConnectCache; | ||
| final String? currentUserMasterPubkey; | ||
| final void Function(ReplaceableEventReference tokenDefinitionEventReference) uiEventQueueCallback; | ||
|
|
||
| String get localStorageKey => 'creator_token_is_live_dialog_shown_$currentUserMasterPubkey'; | ||
|
|
||
| @override | ||
| bool canHandle(EventMessage eventMessage) { | ||
| return eventMessage.kind == CommunityTokenDefinitionEntity.kind; | ||
| } | ||
|
|
||
| @override | ||
| Future<void> handle(EventMessage eventMessage) async { | ||
| final entity = CommunityTokenDefinitionEntity.fromEventMessage(eventMessage); | ||
|
|
||
| if (entity | ||
| case CommunityTokenDefinitionEntity( | ||
| data: CommunityTokenDefinitionIon( | ||
| eventReference: ReplaceableEventReference( | ||
| masterPubkey: final originalEventMasterPubkey, | ||
| kind: UserMetadataEntity.kind | ||
| ), | ||
| type: CommunityTokenDefinitionIonType.firstBuyAction | ||
| ) | ||
| ) | ||
| when originalEventMasterPubkey == currentUserMasterPubkey && | ||
| !(localStorage.getBool(localStorageKey) ?? false)) { | ||
| uiEventQueueCallback(entity.toEventReference()); | ||
| await localStorage.setBool(key: localStorageKey, value: true); | ||
| } | ||
|
|
||
| await ionConnectCache.cache(entity); | ||
| } | ||
| } | ||
|
|
||
| @riverpod | ||
| CommunityTokenDefinitionHandler communityTokenDefinitionHandler(Ref ref) { | ||
| final localStorage = ref.watch(localStorageProvider); | ||
| final cache = ref.watch(ionConnectCacheProvider.notifier); | ||
| final currentUserMasterPubkey = ref.watch(currentPubkeySelectorProvider); | ||
|
|
||
| void uiEventQueueCallback(ReplaceableEventReference tokenDefinitionEventReference) { | ||
| ref | ||
| .read(uiEventQueueNotifierProvider.notifier) | ||
| .emit(CreatorTokenIsLiveDialogEvent(tokenDefinitionEventReference)); | ||
| } | ||
|
|
||
| return CommunityTokenDefinitionHandler( | ||
| ionConnectCache: cache, | ||
| localStorage: localStorage, | ||
| uiEventQueueCallback: uiEventQueueCallback, | ||
| currentUserMasterPubkey: currentUserMasterPubkey, | ||
| ); | ||
| } | ||
174 changes: 174 additions & 0 deletions
174
lib/app/features/tokenized_communities/views/creator_token_is_live_dialog.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| // SPDX-License-Identifier: ice License 1.0 | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_hooks/flutter_hooks.dart'; | ||
| import 'package:go_router/go_router.dart'; | ||
| import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
| import 'package:ion/app/components/avatar/avatar.dart'; | ||
| import 'package:ion/app/components/button/button.dart'; | ||
| import 'package:ion/app/components/gradient_border_painter/gradient_border_painter.dart'; | ||
| import 'package:ion/app/components/progress_bar/ion_loading_indicator.dart'; | ||
| import 'package:ion/app/components/screen_offset/screen_bottom_offset.dart'; | ||
| import 'package:ion/app/components/screen_offset/screen_side_offset.dart'; | ||
| import 'package:ion/app/extensions/extensions.dart'; | ||
| import 'package:ion/app/features/auth/providers/auth_provider.m.dart'; | ||
| import 'package:ion/app/features/feed/views/pages/feed_page/components/stories/mock.dart'; | ||
| import 'package:ion/app/features/ion_connect/model/event_reference.f.dart'; | ||
| import 'package:ion/app/features/tokenized_communities/providers/token_market_info_provider.r.dart'; | ||
| import 'package:ion/app/features/user/model/profile_mode.dart'; | ||
| import 'package:ion/app/features/user/pages/profile_page/components/profile_background.dart'; | ||
| import 'package:ion/app/features/user/pages/profile_page/components/profile_details/user_name_tile/user_name_tile.dart'; | ||
| import 'package:ion/app/features/user/providers/user_metadata_provider.r.dart'; | ||
| import 'package:ion/app/hooks/use_avatar_colors.dart'; | ||
| import 'package:ion/app/router/app_routes.gr.dart'; | ||
| import 'package:ion/app/router/components/navigation_app_bar/navigation_close_button.dart'; | ||
| import 'package:ion/app/router/utils/show_simple_bottom_sheet.dart'; | ||
| import 'package:ion/app/services/logger/logger.dart'; | ||
| import 'package:ion/app/services/ui_event_queue/ui_event_queue_notifier.r.dart'; | ||
| import 'package:ion/generated/assets.gen.dart'; | ||
|
|
||
| class CreatorTokenIsLiveDialogEvent extends UiEvent { | ||
| CreatorTokenIsLiveDialogEvent(this.tokenDefinitionEventReference); | ||
|
|
||
| static bool shown = false; | ||
| final ReplaceableEventReference tokenDefinitionEventReference; | ||
|
|
||
| @override | ||
| void performAction(BuildContext context) { | ||
| if (!shown) { | ||
| shown = true; | ||
| showSimpleBottomSheet<void>( | ||
| context: context, | ||
| backgroundColor: context.theme.appColors.forest, | ||
| child: | ||
| CreatorTokenIsLiveDialog(tokenDefinitionEventReference: tokenDefinitionEventReference), | ||
| ).whenComplete(() => shown = false); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class CreatorTokenIsLiveDialog extends HookConsumerWidget { | ||
| const CreatorTokenIsLiveDialog({required this.tokenDefinitionEventReference, super.key}); | ||
|
|
||
| final ReplaceableEventReference tokenDefinitionEventReference; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context, WidgetRef ref) { | ||
| final avatarUrl = ref.watch(currentUserMetadataProvider).value?.data.avatarUrl; | ||
| final imageColors = useImageColors(avatarUrl); | ||
|
|
||
| return ProfileGradientBackground( | ||
| colors: imageColors ?? useAvatarFallbackColors, | ||
| disableDarkGradient: false, | ||
| child: _ContentState(tokenDefinitionEventReference), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class _ContentState extends HookConsumerWidget { | ||
| const _ContentState(this.tokenDefinitionEventReference); | ||
|
|
||
| final ReplaceableEventReference tokenDefinitionEventReference; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context, WidgetRef ref) { | ||
| final isLoading = useState(false); | ||
| final currentUserMasterPubkey = ref.watch(currentPubkeySelectorProvider) ?? ''; | ||
| final userMetadata = ref.watch(currentUserMetadataProvider).valueOrNull; | ||
| final avatarUrl = userMetadata?.data.avatarUrl ?? ''; | ||
|
|
||
| final eventReferenceString = userMetadata?.toEventReference().toString(); | ||
|
|
||
| final token = eventReferenceString != null | ||
| ? ref.watch(tokenMarketInfoProvider(eventReferenceString)).valueOrNull | ||
| : null; | ||
|
|
||
| return Stack( | ||
| children: [ | ||
| PositionedDirectional( | ||
| bottom: 0, | ||
| start: 0, | ||
| end: 0, | ||
| child: Assets.images.tokenizedCommunities.creatorMonetizationLiveRays | ||
| .iconWithDimensions(width: 461.s, height: 461.s), | ||
| ), | ||
| PositionedDirectional( | ||
| end: 8, | ||
| child: NavigationCloseButton(color: context.theme.appColors.onPrimaryAccent), | ||
| ), | ||
| ScreenSideOffset.medium( | ||
| child: Column( | ||
| children: [ | ||
| SizedBox(height: 30.0.s), | ||
| CustomPaint( | ||
| painter: GradientBorderPainter( | ||
| strokeWidth: 2.0.s, | ||
| cornerRadius: 26.0.s, | ||
| gradient: storyBorderGradients[3], | ||
ice-damocles marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| backgroundColor: context.theme.appColors.forest.withAlpha(125), | ||
| ), | ||
| child: Padding( | ||
| padding: EdgeInsets.all(18.0.s), | ||
| child: Avatar( | ||
| size: 64.0.s, | ||
| fit: BoxFit.cover, | ||
| imageUrl: avatarUrl, | ||
| borderRadius: BorderRadius.all(Radius.circular(16.0.s)), | ||
| ), | ||
| ), | ||
| ), | ||
| SizedBox(height: 8.0.s), | ||
| UserNameTile( | ||
| showProfileTokenPrice: true, | ||
| profileMode: ProfileMode.dark, | ||
| pubkey: currentUserMasterPubkey, | ||
| priceUsd: token?.marketData.priceUSD, | ||
| ), | ||
| SizedBox(height: 18.0.s), | ||
| Text( | ||
| context.i18n.tokenized_community_creator_token_live_title, | ||
| textAlign: TextAlign.center, | ||
| style: context.theme.appTextThemes.title | ||
| .copyWith(color: context.theme.appColors.onPrimaryAccent), | ||
| ), | ||
| SizedBox(height: 8.0.s), | ||
| Text( | ||
| context.i18n.tokenized_community_creator_token_live_subtitle, | ||
| textAlign: TextAlign.center, | ||
| style: context.theme.appTextThemes.body2 | ||
| .copyWith(color: context.theme.appColors.secondaryBackground), | ||
| ), | ||
| SizedBox(height: 24.0.s), | ||
| Button( | ||
| disabled: isLoading.value, | ||
| label: Text(context.i18n.button_share), | ||
| minimumSize: Size(double.infinity, 56.0.s), | ||
| trailingIcon: | ||
| isLoading.value ? const IONLoadingIndicator() : const SizedBox.shrink(), | ||
| onPressed: token != null | ||
| ? () async { | ||
| isLoading.value = true; | ||
| try { | ||
| if (context.mounted) { | ||
| context.pop(); | ||
|
|
||
| await ShareViaMessageModalRoute( | ||
| eventReference: tokenDefinitionEventReference.encode(), | ||
| ).push<void>(context); | ||
| } | ||
| } catch (e, st) { | ||
| Logger.error(e, stackTrace: st); | ||
| } finally { | ||
| isLoading.value = false; | ||
| } | ||
| } | ||
| : null, | ||
| ), | ||
| ScreenBottomOffset(), | ||
| ], | ||
| ), | ||
| ), | ||
| ], | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.