Skip to content

Commit

Permalink
Merge pull request #1414 from bitmark-inc/merch_check_product
Browse files Browse the repository at this point in the history
show merch if product is not empty
  • Loading branch information
phuocbitmark authored Dec 14, 2023
2 parents ec0868f + 87a29cd commit 5e05f03
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 128 deletions.
1 change: 1 addition & 0 deletions .github/workflows/android-release-appcenter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
echo TZKT_MAINNET_URL=${{ secrets.TZKT_MAINNET_URL }} >> .env
${{ github.event.inputs.testnet == 'true' }} && echo POSTCARD_CONTRACT_ADDRESS=${{ secrets.POSTCARD_CONTRACT_ADDRESS_TESTNET }} >> .env || echo POSTCARD_CONTRACT_ADDRESS=${{ secrets.POSTCARD_CONTRACT_ADDRESS_MAINNET }} >> .env
${{ github.event.inputs.testnet == 'true' }} && echo AUTONOMY_MERCHANDISE_BASE_URL=${{ secrets.AUTONOMY_MERCHANDISE_BASE_URL_TESTNET }} >> .env || echo AUTONOMY_MERCHANDISE_BASE_URL=${{ secrets.AUTONOMY_MERCHANDISE_BASE_URL_MAINNET }} >> .env
${{ github.event.inputs.testnet == 'true' }} && echo AUTONOMY_MERCHANDISE_API_URL=${{ secrets.AUTONOMY_MERCHANDISE_API_URL_TESTNET }} >> .env || echo AUTONOMY_MERCHANDISE_API_URL=${{ secrets.AUTONOMY_MERCHANDISE_API_URL_MAINNET }} >> .env
${{ github.event.inputs.testnet == 'true' }} && echo PAY_TO_MINT_BASE_URL=${{ secrets.PAY_TO_MINT_BASE_URL_TESTNET }} >> .env || echo PAY_TO_MINT_BASE_URL=${{ secrets.PAY_TO_MINT_BASE_URL_MAINNET }} >> .env
${{ github.event.inputs.testnet == 'true' }} && echo AUTONOMY_PUBDOC_URL=${{ secrets.AUTONOMY_PUBDOC_URL_DEV }} >> .env || echo AUTONOMY_PUBDOC_URL=${{ secrets.AUTONOMY_PUBDOC_URL_PRD }} >> .env
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/bmvn_build_appcenter_android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ jobs:
echo TZKT_MAINNET_URL=${{ secrets.TZKT_MAINNET_URL }} >> .env
${{ inputs.testnet == true }} && echo POSTCARD_CONTRACT_ADDRESS=${{ secrets.POSTCARD_CONTRACT_ADDRESS_TESTNET }} >> .env || echo POSTCARD_CONTRACT_ADDRESS=${{ secrets.POSTCARD_CONTRACT_ADDRESS_MAINNET }} >> .env
${{ inputs.testnet == true }} && echo AUTONOMY_MERCHANDISE_BASE_URL=${{ secrets.AUTONOMY_MERCHANDISE_BASE_URL_TESTNET }} >> .env || echo AUTONOMY_MERCHANDISE_BASE_URL=${{ secrets.AUTONOMY_MERCHANDISE_BASE_URL_MAINNET }} >> .env
${{ inputs.testnet == true }} && echo AUTONOMY_MERCHANDISE_API_URL=${{ secrets.AUTONOMY_MERCHANDISE_API_URL_TESTNET }} >> .env || echo AUTONOMY_MERCHANDISE_API_URL=${{ secrets.AUTONOMY_MERCHANDISE_API_URL_MAINNET }} >> .env
${{ inputs.testnet == true }} && echo PAY_TO_MINT_BASE_URL=${{ secrets.PAY_TO_MINT_BASE_URL_TESTNET }} >> .env || echo PAY_TO_MINT_BASE_URL=${{ secrets.PAY_TO_MINT_BASE_URL_MAINNET }} >> .env
${{ inputs.testnet == true }} && echo AUTONOMY_PUBDOC_URL=${{ secrets.AUTONOMY_PUBDOC_URL_DEV }} >> .env || echo AUTONOMY_PUBDOC_URL=${{ secrets.AUTONOMY_PUBDOC_URL_PRD }} >> .env
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/bmvn_build_appcenter_ios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ jobs:
echo TZKT_MAINNET_URL=${{ secrets.TZKT_MAINNET_URL }} >> .env
${{ inputs.testnet == true }} && echo POSTCARD_CONTRACT_ADDRESS=${{ secrets.POSTCARD_CONTRACT_ADDRESS_TESTNET }} >> .env || echo POSTCARD_CONTRACT_ADDRESS=${{ secrets.POSTCARD_CONTRACT_ADDRESS_MAINNET }} >> .env
${{ inputs.testnet == true }} && echo AUTONOMY_MERCHANDISE_BASE_URL=${{ secrets.AUTONOMY_MERCHANDISE_BASE_URL_TESTNET }} >> .env || echo AUTONOMY_MERCHANDISE_BASE_URL=${{ secrets.AUTONOMY_MERCHANDISE_BASE_URL_MAINNET }} >> .env
${{ inputs.testnet == true }} && echo AUTONOMY_MERCHANDISE_API_URL=${{ secrets.AUTONOMY_MERCHANDISE_API_URL_TESTNET }} >> .env || echo AUTONOMY_MERCHANDISE_API_URL=${{ secrets.AUTONOMY_MERCHANDISE_API_URL_MAINNET }} >> .env
${{ inputs.testnet == true }} && echo PAY_TO_MINT_BASE_URL=${{ secrets.PAY_TO_MINT_BASE_URL_TESTNET }} >> .env || echo PAY_TO_MINT_BASE_URL=${{ secrets.PAY_TO_MINT_BASE_URL_MAINNET }} >> .env
${{ inputs.testnet == true }} && echo AUTONOMY_PUBDOC_URL=${{ secrets.AUTONOMY_PUBDOC_URL_DEV }} >> .env || echo AUTONOMY_PUBDOC_URL=${{ secrets.AUTONOMY_PUBDOC_URL_PRD }} >> .env
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ios-release-appstore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ jobs:
echo TZKT_MAINNET_URL=${{ secrets.TZKT_MAINNET_URL }} >> .env
${{ github.event.inputs.testnet == 'true' }} && echo POSTCARD_CONTRACT_ADDRESS=${{ secrets.POSTCARD_CONTRACT_ADDRESS_TESTNET }} >> .env || echo POSTCARD_CONTRACT_ADDRESS=${{ secrets.POSTCARD_CONTRACT_ADDRESS_MAINNET }} >> .env
${{ github.event.inputs.testnet == 'true' }} && echo AUTONOMY_MERCHANDISE_BASE_URL=${{ secrets.AUTONOMY_MERCHANDISE_BASE_URL_TESTNET }} >> .env || echo AUTONOMY_MERCHANDISE_BASE_URL=${{ secrets.AUTONOMY_MERCHANDISE_BASE_URL_MAINNET }} >> .env
${{ github.event.inputs.testnet == 'true' }} && echo AUTONOMY_MERCHANDISE_API_URL=${{ secrets.AUTONOMY_MERCHANDISE_API_URL_TESTNET }} >> .env || echo AUTONOMY_MERCHANDISE_API_URL=${{ secrets.AUTONOMY_MERCHANDISE_API_URL_MAINNET }} >> .env
${{ github.event.inputs.testnet == 'true' }} && echo PAY_TO_MINT_BASE_URL=${{ secrets.PAY_TO_MINT_BASE_URL_TESTNET }} >> .env || echo PAY_TO_MINT_BASE_URL=${{ secrets.PAY_TO_MINT_BASE_URL_MAINNET }} >> .env
${{ github.event.inputs.testnet == 'true' }} && echo AUTONOMY_PUBDOC_URL=${{ secrets.AUTONOMY_PUBDOC_URL_DEV }} >> .env || echo AUTONOMY_PUBDOC_URL=${{ secrets.AUTONOMY_PUBDOC_URL_PRD }} >> .env
Expand Down
2 changes: 2 additions & 0 deletions lib/common/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// that can be found in the LICENSE file.
//

// ignore_for_file: cascade_invocations

import 'dart:math';

import 'package:autonomy_flutter/common/environment.dart';
Expand Down
3 changes: 3 additions & 0 deletions lib/gateway/postcard_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ abstract class PostcardApi {
@GET('/v1/postcard/claim/{share_code}')
Future claimShareCode(@Path('share_code') String shareCode);

@GET('/v1/postcard/{token_id}/merchandise_enabled')
Future<String> getMerchandiseEnable(@Path('token_id') String tokenId);

@MultiPart()
@POST('/v1/postcard/{token_id}/stamp')
Future<dynamic> updatePostcard({
Expand Down
26 changes: 26 additions & 0 deletions lib/gateway/postcard_api.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 14 additions & 31 deletions lib/screen/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ class AppRouter {
injector<AuditService>(),
);
final identityBloc = IdentityBloc(injector<AppDatabase>(), injector());
final postcardDetailBloc = PostcardDetailBloc(
injector(),
injector(),
injector(),
injector(),
injector(),
injector(),
injector(),
injector(),
);

switch (settings.name) {
case viewPlayListPage:
Expand Down Expand Up @@ -382,15 +392,7 @@ class AppRouter {
child: MultiBlocProvider(
providers: [
BlocProvider(create: (_) => identityBloc),
BlocProvider(
create: (_) => PostcardDetailBloc(
injector(),
injector(),
injector(),
injector(),
injector(),
injector(),
)),
BlocProvider(create: (_) => postcardDetailBloc),
],
child: StampPreview(
payload: settings.arguments! as StampPreviewPayload),
Expand Down Expand Up @@ -587,9 +589,7 @@ class AppRouter {
injector(),
),
),
BlocProvider(
create: (_) => PostcardDetailBloc(injector(), injector(),
injector(), injector(), injector(), injector())),
BlocProvider(create: (_) => postcardDetailBloc),
],
child: ArtworkPreviewPage(
payload: settings.arguments! as ArtworkDetailPayload,
Expand Down Expand Up @@ -683,15 +683,7 @@ class AppRouter {
BlocProvider.value(value: accountsBloc),
BlocProvider(create: (_) => identityBloc),
BlocProvider(create: (_) => TravelInfoBloc()),
BlocProvider(
create: (_) => PostcardDetailBloc(
injector(),
injector(),
injector(),
injector(),
injector(),
injector(),
)),
BlocProvider(create: (_) => postcardDetailBloc),
],
child: ClaimedPostcardDetailPage(
key: payload.key, payload: payload)));
Expand Down Expand Up @@ -1132,16 +1124,7 @@ class AppRouter {
child: MultiBlocProvider(
providers: [
BlocProvider.value(value: accountsBloc),
BlocProvider(
create: (_) => PostcardDetailBloc(
injector(),
injector(),
injector(),
injector(),
injector(),
injector(),
),
),
BlocProvider(create: (_) => postcardDetailBloc),
],
child: PostcardLeaderboardPage(
payload: settings.arguments! as PostcardLeaderboardPagePayload,
Expand Down
4 changes: 2 additions & 2 deletions lib/screen/detail/preview_detail/preview_detail_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ class PostcardPreviewWidget extends StatefulWidget {

class _PostcardPreviewWidgetState extends State<PostcardPreviewWidget>
with WidgetsBindingObserver, RouteAware {
final bloc = PostcardDetailBloc(
injector(), injector(), injector(), injector(), injector(), injector());
final bloc = PostcardDetailBloc(injector(), injector(), injector(),
injector(), injector(), injector(), injector(), injector());

@override
void initState() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:autonomy_flutter/common/environment.dart';
import 'package:autonomy_flutter/common/injector.dart';
import 'package:autonomy_flutter/model/postcard_claim.dart';
import 'package:autonomy_flutter/model/postcard_metadata.dart';
import 'package:autonomy_flutter/model/prompt.dart';
import 'package:autonomy_flutter/screen/app_router.dart';
import 'package:autonomy_flutter/service/account_service.dart';
import 'package:autonomy_flutter/service/configuration_service.dart';
Expand Down Expand Up @@ -35,13 +34,7 @@ class ClaimEmptyPostCardBloc
on<GetTokenEvent>((event, emit) async {
final indexId = event.claimRequest.tokenId;
final tokenId = 'tez-${Environment.postcardContractAddress}-$indexId';
late final Prompt? prompt;
try {
final prompts = await _postcardService.getPrompts(indexId);
prompt = prompts.isNotEmpty ? prompts.first : null;
} catch (e) {
prompt = null;
}
final prompt = await _postcardService.getPrompt(indexId);
final postcardMetadata = PostcardMetadata(
prompt: prompt,
locationInformation: [],
Expand Down
68 changes: 55 additions & 13 deletions lib/screen/interactive_postcard/postcard_detail_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import 'dart:async';

import 'package:autonomy_flutter/au_bloc.dart';
import 'package:autonomy_flutter/common/injector.dart';
import 'package:autonomy_flutter/model/pair.dart';
import 'package:autonomy_flutter/screen/detail/artwork_detail_page.dart';
import 'package:autonomy_flutter/screen/interactive_postcard/leaderboard/postcard_leaderboard.dart';
import 'package:autonomy_flutter/screen/interactive_postcard/postcard_detail_state.dart';
import 'package:autonomy_flutter/service/configuration_service.dart';
import 'package:autonomy_flutter/service/postcard_service.dart';
import 'package:autonomy_flutter/service/remote_config_service.dart';
import 'package:autonomy_flutter/util/asset_token_ext.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/distance_formater.dart';
Expand Down Expand Up @@ -47,6 +47,8 @@ class PostcardDetailBloc
final IndexerService _indexerService;
final PostcardService _postcardService;
final ConfigurationService _configurationService;
final TokensService _tokenService;
final RemoteConfigService _remoteConfig;

PostcardDetailBloc(
this._assetTokenDao,
Expand All @@ -55,6 +57,8 @@ class PostcardDetailBloc
this._indexerService,
this._postcardService,
this._configurationService,
this._tokenService,
this._remoteConfig,
) : super(PostcardDetailState(provenances: [])) {
on<PostcardDetailGetInfoEvent>((event, emit) async {
if (event.useIndexer) {
Expand All @@ -72,17 +76,19 @@ class PostcardDetailBloc
assetToken.first.setAssetPrompt(tempsPrompt);
}
final paths = getUpdatingPath(assetToken.first);

emit(state.copyWith(
assetToken: assetToken.first,
provenances: assetToken.first.provenance,
imagePath: paths.first,
metadataPath: paths.second,
showMerch: false,
enableMerch: false,
));
}
return;
} else {
final tokenService = injector<TokensService>();
unawaited(tokenService.reindexAddresses([event.identity.owner]));
unawaited(_tokenService.reindexAddresses([event.identity.owner]));
final assetToken = await _assetTokenDao.findAssetTokenByIdAndOwner(
event.identity.id, event.identity.owner);
if (assetToken == null) {
Expand All @@ -96,14 +102,30 @@ class PostcardDetailBloc
assetToken?.setAssetPrompt(tempsPrompt);
}
final paths = getUpdatingPath(assetToken);
emit(state.copyWith(
assetToken: assetToken,
imagePath: paths.first,
metadataPath: paths.second));
final isViewOnly = await assetToken?.isViewOnly();
emit(
state.copyWith(
assetToken: assetToken,
imagePath: paths.first,
metadataPath: paths.second,
isViewOnly: isViewOnly),
);

final provenances =
await _provenanceDao.findProvenanceByTokenID(event.identity.id);
emit(state.copyWith(provenances: provenances));
final showProvenances =
_remoteConfig.getBool(ConfigGroup.viewDetail, ConfigKey.provenance);
if (showProvenances) {
final provenances =
await _provenanceDao.findProvenanceByTokenID(event.identity.id);
emit(state.copyWith(provenances: provenances));
}

final showMerch =
await _showMerchProduct(assetToken, isViewOnly ?? true);
if (showMerch != state.showMerch) {
emit(state.copyWith(
showMerch: showMerch,
enableMerch: assetToken?.enabledMerch ?? false));
}

if (assetToken != null &&
assetToken.asset != null &&
Expand Down Expand Up @@ -167,9 +189,8 @@ class PostcardDetailBloc
String? imagePath;
String? metadataPath;
if (asset != null) {
final postcardService = injector<PostcardService>();
final stampingPostcard =
postcardService.getStampingPostcardWithPath(asset.stampingPostcard!);
_postcardService.getStampingPostcardWithPath(asset.stampingPostcard!);
final processingStampPostcard = asset.processingStampPostcard;
final isStamped = asset.isStamped;
if (!isStamped) {
Expand All @@ -186,7 +207,7 @@ class PostcardDetailBloc
}
} else {
if (stampingPostcard != null) {
unawaited(postcardService
unawaited(_postcardService
.updateStampingPostcard([stampingPostcard], isRemove: true));
}
if (processingStampPostcard != null) {
Expand All @@ -198,4 +219,25 @@ class PostcardDetailBloc
}
return Pair(imagePath, metadataPath);
}

Future<bool> _showMerchProduct(AssetToken? asset, bool isViewOnly) async {
if (asset == null) {
return false;
}
final isShowConfig =
_remoteConfig.getBool(ConfigGroup.merchandise, ConfigKey.enable) &&
(_remoteConfig.getBool(
ConfigGroup.merchandise, ConfigKey.allowViewOnly) ||
!isViewOnly);
if (!isShowConfig) {
return false;
}
try {
final enableMerch =
await _postcardService.isMerchandiseEnable(asset.tokenId ?? '');
return enableMerch;
} catch (e) {
return false;
}
}
}
Loading

0 comments on commit 5e05f03

Please sign in to comment.