From 3446fc2c73b17ffdfe45e69e9eb96dfaed02fb2f Mon Sep 17 00:00:00 2001 From: phuoc Date: Wed, 13 Dec 2023 16:52:51 +0700 Subject: [PATCH] fix add prompt to metadata Signed-off-by: phuoc --- .../claim_empty_postcard_bloc.dart | 9 +-------- lib/service/postcard_service.dart | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/screen/interactive_postcard/claim_empty_postcard/claim_empty_postcard_bloc.dart b/lib/screen/interactive_postcard/claim_empty_postcard/claim_empty_postcard_bloc.dart index 367fe7d1e..2b26ecdb3 100644 --- a/lib/screen/interactive_postcard/claim_empty_postcard/claim_empty_postcard_bloc.dart +++ b/lib/screen/interactive_postcard/claim_empty_postcard/claim_empty_postcard_bloc.dart @@ -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'; @@ -35,13 +34,7 @@ class ClaimEmptyPostCardBloc on((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: [], diff --git a/lib/service/postcard_service.dart b/lib/service/postcard_service.dart index 92cb8636b..cf37ba6f6 100644 --- a/lib/service/postcard_service.dart +++ b/lib/service/postcard_service.dart @@ -112,7 +112,7 @@ abstract class PostcardService { Future finalizeStamp(AssetToken asset, String imagePath, String metadataPath, Location location); - Future> getPrompts(String tokenId); + Future getPrompt(String tokenId); } class PostcardServiceImpl extends PostcardService { @@ -538,7 +538,9 @@ class PostcardServiceImpl extends PostcardService { 'postcardId': result.tokenID, })); final tokenID = 'tez-${result.contractAddress}-${result.tokenID}'; + final prompt = await getPrompt(result.tokenID ?? ''); final postcardMetadata = PostcardMetadata( + prompt: prompt, locationInformation: [], ); final token = AssetToken( @@ -550,7 +552,7 @@ class PostcardServiceImpl extends PostcardService { title: requestPostcardResponse.name, previewURL: requestPostcardResponse.previewURL, source: 'postcard', - artworkMetadata: jsonEncode(postcardMetadata.toJson()), + artworkMetadata: jsonEncode(postcardMetadata), medium: 'software', ), blockchain: 'tezos', @@ -688,10 +690,15 @@ class PostcardServiceImpl extends PostcardService { } @override - Future> getPrompts(String tokenId) async { - final prompts = await _postcardApi.getPrompts(tokenId); - log.info('[POSTCARD] getPrompts: $prompts'); - return prompts; + Future getPrompt(String tokenId) async { + try { + final prompts = await _postcardApi.getPrompts(tokenId); + log.info('[POSTCARD] getPrompts: $prompts'); + final prompt = prompts.isNotEmpty ? prompts.first : null; + return prompt; + } catch (e) { + return null; + } } }