Skip to content

Commit

Permalink
fix add prompt to metadata
Browse files Browse the repository at this point in the history
Signed-off-by: phuoc <[email protected]>
  • Loading branch information
phuocbitmark committed Dec 13, 2023
1 parent c2445f4 commit 3446fc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
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
19 changes: 13 additions & 6 deletions lib/service/postcard_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ abstract class PostcardService {
Future<bool> finalizeStamp(AssetToken asset, String imagePath,
String metadataPath, Location location);

Future<List<Prompt>> getPrompts(String tokenId);
Future<Prompt?> getPrompt(String tokenId);
}

class PostcardServiceImpl extends PostcardService {
Expand Down Expand Up @@ -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(
Expand All @@ -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',
Expand Down Expand Up @@ -688,10 +690,15 @@ class PostcardServiceImpl extends PostcardService {
}

@override
Future<List<Prompt>> getPrompts(String tokenId) async {
final prompts = await _postcardApi.getPrompts(tokenId);
log.info('[POSTCARD] getPrompts: $prompts');
return prompts;
Future<Prompt?> 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;
}
}
}

Expand Down

0 comments on commit 3446fc2

Please sign in to comment.