diff --git a/lib/screen/interactive_postcard/postcard_detail_bloc.dart b/lib/screen/interactive_postcard/postcard_detail_bloc.dart index 58d451345..af0076ad8 100644 --- a/lib/screen/interactive_postcard/postcard_detail_bloc.dart +++ b/lib/screen/interactive_postcard/postcard_detail_bloc.dart @@ -32,10 +32,8 @@ abstract class PostcardDetailEvent {} class PostcardDetailGetInfoEvent extends PostcardDetailEvent { final ArtworkIdentity identity; final bool useIndexer; - final bool isFromLeaderboard; - PostcardDetailGetInfoEvent(this.identity, - {this.useIndexer = false, this.isFromLeaderboard = false}); + PostcardDetailGetInfoEvent(this.identity, {this.useIndexer = false}); } class FetchLeaderboardEvent extends PostcardDetailEvent {} @@ -64,9 +62,9 @@ class PostcardDetailBloc this._tokenService, this._merchandiseApi, this._remoteConfig, - ) : super(PostcardDetailState(provenances: [], isViewOnly: true)) { + ) : super(PostcardDetailState(provenances: [])) { on((event, emit) async { - if (event.useIndexer || event.isFromLeaderboard) { + if (event.useIndexer) { final request = QueryListTokensRequest( owners: [event.identity.owner], ); @@ -82,21 +80,14 @@ class PostcardDetailBloc } final paths = getUpdatingPath(assetToken.first); - final isViewOnly = - await _isViewOnly(assetToken.first, event.isFromLeaderboard); emit(state.copyWith( assetToken: assetToken.first, provenances: assetToken.first.provenance, imagePath: paths.first, metadataPath: paths.second, - isViewOnly: isViewOnly, + showMerch: false, + enableMerch: false, )); - - final hasMerch = - await _showMerchProduct(assetToken.first, isViewOnly); - if (hasMerch != state.showMerch) { - emit(state.copyWith(showMerch: hasMerch)); - } } return; } else { @@ -114,8 +105,7 @@ class PostcardDetailBloc assetToken?.setAssetPrompt(tempsPrompt); } final paths = getUpdatingPath(assetToken); - final isViewOnly = - await _isViewOnly(assetToken, event.isFromLeaderboard); + final isViewOnly = await _isViewOnly(assetToken); emit( state.copyWith( assetToken: assetToken, @@ -132,9 +122,12 @@ class PostcardDetailBloc emit(state.copyWith(provenances: provenances)); } - final hasMerch = await _showMerchProduct(assetToken, isViewOnly); - if (hasMerch != state.showMerch) { - emit(state.copyWith(showMerch: hasMerch)); + final showMerch = + await _showMerchProduct(assetToken, isViewOnly ?? true); + if (showMerch != state.showMerch) { + emit(state.copyWith( + showMerch: showMerch, + enableMerch: showMerch && _enableMerch(assetToken))); } if (assetToken != null && @@ -230,24 +223,22 @@ class PostcardDetailBloc return Pair(imagePath, metadataPath); } - Future _isViewOnly(AssetToken? asset, bool isFromLeaderboard) async { + Future _isViewOnly(AssetToken? asset) async { if (asset == null) { - return true; + return null; } - return (await asset.isViewOnly()) || isFromLeaderboard; + return await asset.isViewOnly(); } Future _showMerchProduct(AssetToken? asset, bool isViewOnly) async { if (asset == null) { return false; } - final isShowConfig = (asset.isCompleted || - !_remoteConfig.getBool( - ConfigGroup.merchandise, ConfigKey.mustCompleted)) && + final isShowConfig = _remoteConfig.getBool(ConfigGroup.merchandise, ConfigKey.enable) && - (_remoteConfig.getBool( - ConfigGroup.merchandise, ConfigKey.allowViewOnly) || - !isViewOnly); + (_remoteConfig.getBool( + ConfigGroup.merchandise, ConfigKey.allowViewOnly) || + !isViewOnly); if (!isShowConfig) { return false; } @@ -255,7 +246,17 @@ class PostcardDetailBloc final products = await _merchandiseApi.getProducts(asset.id); return products.isNotEmpty; } catch (e) { + return true; + } + } + + bool _enableMerch(AssetToken? asset) { + if (asset == null) { return false; } + final isEnable = asset.isCompleted || + !_remoteConfig.getBool( + ConfigGroup.merchandise, ConfigKey.mustCompleted); + return isEnable; } } diff --git a/lib/screen/interactive_postcard/postcard_detail_page.dart b/lib/screen/interactive_postcard/postcard_detail_page.dart index cf6efa040..c4f44334a 100644 --- a/lib/screen/interactive_postcard/postcard_detail_page.dart +++ b/lib/screen/interactive_postcard/postcard_detail_page.dart @@ -98,7 +98,7 @@ class ClaimedPostcardDetailPageState extends State with AfterLayoutMixin { late ScrollController _scrollController; late bool withSharing; - late bool isViewOnly; + late bool isNotOwner; late bool isSending; late bool alreadyShowPopup; late bool isProcessingStampPostcard; @@ -118,7 +118,7 @@ class ClaimedPostcardDetailPageState extends State @override void initState() { _scrollController = ScrollController(); - isViewOnly = widget.payload.isFromLeaderboard; + isNotOwner = widget.payload.isFromLeaderboard; isSending = false; alreadyShowPopup = false; isProcessingStampPostcard = false; @@ -127,8 +127,8 @@ class ClaimedPostcardDetailPageState extends State context.read().add( PostcardDetailGetInfoEvent( widget.payload.identities[widget.payload.currentIndex], - useIndexer: widget.payload.isFromLeaderboard, - isFromLeaderboard: widget.payload.useIndexer), + useIndexer: widget.payload.useIndexer || + widget.payload.isFromLeaderboard), ); context.read().add(FetchLeaderboardEvent()); context.read().add(FetchAllAddressesEvent()); @@ -304,7 +304,8 @@ class ClaimedPostcardDetailPageState extends State if (previous.assetToken?.isCompleted != true && current.assetToken?.isCompleted == true && current.assetToken?.isAlreadyShowYouDidIt == false && - !isViewOnly) { + !isNotOwner && + current.isViewOnly == false) { unawaited(_youDidIt(context, current.assetToken!)); } return true; @@ -340,10 +341,10 @@ class ClaimedPostcardDetailPageState extends State } setState(() { currentAsset = state.assetToken; - isViewOnly = state.isViewOnly; + isNotOwner = isNotOwner || (state.isViewOnly ?? true); isSending = state.assetToken?.isSending ?? false; }); - if (isViewOnly) { + if (isNotOwner) { return; } if (withSharing) { @@ -431,8 +432,8 @@ class ClaimedPostcardDetailPageState extends State child: Semantics( label: 'artworkDotIcon', child: IconButton( - onPressed: () => unawaited(_showArtworkOptionsDialog( - context, asset, state.isViewOnly)), + onPressed: () => unawaited( + _showArtworkOptionsDialog(context, asset)), constraints: const BoxConstraints( maxWidth: 44, maxHeight: 44, @@ -623,7 +624,7 @@ class ClaimedPostcardDetailPageState extends State 'place_15_stamps'.tr(), style: theme.textTheme.moMASans400Black12, ); - if (asset.isCompleted || isViewOnly || !asset.isLastOwner) { + if (asset.isCompleted || isNotOwner || !asset.isLastOwner) { return const SizedBox(); } if (isProcessingStampPostcard || @@ -917,7 +918,7 @@ class ClaimedPostcardDetailPageState extends State ); Future _showArtworkOptionsDialog( - BuildContext context, AssetToken asset, bool isViewOnly) async { + BuildContext context, AssetToken asset) async { final theme = Theme.of(context); if (!mounted) { return; @@ -961,7 +962,7 @@ class ClaimedPostcardDetailPageState extends State Navigator.of(context).pop(); }, ), - if (!isViewOnly) ...[ + if (!isNotOwner) ...[ if (_remoteConfig.getBool( ConfigGroup.feature, ConfigKey.downloadStamp)) OptionItem( diff --git a/lib/screen/interactive_postcard/postcard_detail_state.dart b/lib/screen/interactive_postcard/postcard_detail_state.dart index 5cdd9cacf..07e5c4669 100644 --- a/lib/screen/interactive_postcard/postcard_detail_state.dart +++ b/lib/screen/interactive_postcard/postcard_detail_state.dart @@ -18,17 +18,19 @@ class PostcardDetailState { PostcardLeaderboard? leaderboard; bool isFetchingLeaderboard; bool? showMerch; - bool isViewOnly; + bool? enableMerch; + bool? isViewOnly; PostcardDetailState({ required this.provenances, - required this.isViewOnly, + this.isViewOnly, this.assetToken, this.imagePath, this.metadataPath, this.leaderboard, this.isFetchingLeaderboard = false, this.showMerch, + this.enableMerch, }); ArtworkDetailState toArtworkDetailState() => ArtworkDetailState( @@ -45,6 +47,7 @@ class PostcardDetailState { bool? isFetchingLeaderboard, bool? showMerch, bool? isViewOnly, + bool? enableMerch, }) => PostcardDetailState( assetToken: assetToken ?? this.assetToken, @@ -56,5 +59,6 @@ class PostcardDetailState { isFetchingLeaderboard ?? this.isFetchingLeaderboard, showMerch: showMerch ?? this.showMerch, isViewOnly: isViewOnly ?? this.isViewOnly, + enableMerch: enableMerch ?? this.enableMerch, ); }