Skip to content

Commit

Permalink
Merge branch 'develop' into Sang/fix/calc_fee_error_message
Browse files Browse the repository at this point in the history
  • Loading branch information
ppupha committed Dec 14, 2023
2 parents 5e8984f + 2de1794 commit 2042d41
Show file tree
Hide file tree
Showing 20 changed files with 660 additions and 511 deletions.
63 changes: 44 additions & 19 deletions lib/model/shared_postcard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
// Use of this source code is governed by the BSD-2-Clause Plus Patent License
// that can be found in the LICENSE file.
//
import 'package:autonomy_flutter/common/injector.dart';
import 'package:autonomy_flutter/util/asset_token_ext.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:collection/collection.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:nft_collection/database/dao/asset_token_dao.dart';

@JsonSerializable()
class SharedPostcard {
Expand All @@ -24,35 +29,55 @@ class SharedPostcard {
owner == other.owner;

// fromJson method
factory SharedPostcard.fromJson(Map<String, dynamic> json) {
return SharedPostcard(
json["tokenID"] as String,
json["owner"] as String,
json["sharedAt"] == null
? null
: DateTime.parse(json["sharedAt"] as String),
);
}
factory SharedPostcard.fromJson(Map<String, dynamic> json) => SharedPostcard(
json['tokenID'] as String,
json['owner'] as String,
json['sharedAt'] == null
? null
: DateTime.parse(json['sharedAt'] as String),
);

Map<String, dynamic> toJson() => {
'tokenID': tokenID,
'owner': owner,
'sharedAt': sharedAt?.toIso8601String(),
};

Map<String, dynamic> toJson() {
return {
"tokenID": tokenID,
"owner": owner,
"sharedAt": sharedAt?.toIso8601String(),
};
bool get isExpired {
if (sharedAt == null) {
return false;
}
return sharedAt!
.add(POSTCARD_SHARE_LINK_VALID_DURATION)
.isBefore(DateTime.now());
}

@override
int get hashCode {
return tokenID.hashCode ^ owner.hashCode;
int get hashCode => tokenID.hashCode ^ owner.hashCode;
}

extension ListSharedPostcard on List<SharedPostcard> {
Future<List<SharedPostcard>> get expiredPostcards async {
final expiredPostcards = <SharedPostcard>[];
await Future.wait(map((postcard) async {
if (postcard.isExpired) {
final token = await injector<AssetTokenDao>()
.findAssetTokenByIdAndOwner(postcard.tokenID, postcard.owner);
if (token != null &&
token.getArtists.lastOrNull?.id == postcard.owner) {
expiredPostcards.add(postcard);
}
}
}));
return expiredPostcards;
}
}

extension Unique<E, Id> on List<E> {
List<E> unique([Id Function(E element)? id, bool inplace = true]) {
final ids = <Id>{};
var list = inplace ? this : List<E>.from(this);
list.retainWhere((x) => ids.add(id != null ? id(x) : x as Id));
var list = inplace ? this : List<E>.from(this)
..retainWhere((x) => ids.add(id != null ? id(x) : x as Id));
return list;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _ClaimEmptyPostCardScreenState extends State<ClaimEmptyPostCardScreen> {
listener: (context, state) {
if (state.isClaimed == true) {
unawaited(injector<NavigationService>()
.selectPromptsThenStamp(context, state.assetToken!));
.selectPromptsThenStamp(context, state.assetToken!, null));
}
if (state.error != null) {
_handleError(state.error!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ class _PayToMintPostcardScreenState extends State<PayToMintPostcardScreen> {
enabled: state.isClaiming != true,
isProcessing: state.isClaiming == true,
onTap: () {
unawaited(injector<NavigationService>()
.selectPromptsThenStamp(
context,
state.assetToken!.copyWith(
owner: widget.claimRequest.address,
tokenId: widget.claimRequest.tokenId)));
unawaited(
injector<NavigationService>().selectPromptsThenStamp(
context,
state.assetToken!.copyWith(
owner: widget.claimRequest.address,
tokenId: widget.claimRequest.tokenId),
null,
));
},
color: POSTCARD_GREEN_BUTTON_COLOR,
),
Expand Down
9 changes: 5 additions & 4 deletions lib/screen/interactive_postcard/design_stamp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ class _DesignStampPageState extends State<DesignStampPage> {
await Navigator.of(context).pushNamed(
HandSignaturePage.handSignaturePage,
arguments: HandSignaturePayload(
bytes!,
widget.payload.asset,
));
bytes!,
widget.payload.asset,
widget.payload.shareCode));

setState(() {
_line = true;
Expand Down Expand Up @@ -438,6 +438,7 @@ class StampPainter extends CustomPainter {
class DesignStampPayload {
final AssetToken asset;
final bool allowPop;
final String? shareCode;

DesignStampPayload(this.asset, this.allowPop);
DesignStampPayload(this.asset, this.allowPop, this.shareCode);
}
5 changes: 4 additions & 1 deletion lib/screen/interactive_postcard/hand_signature_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ class _HandSignaturePageState extends State<HandSignaturePage> {
imagePath: imageDataFile.path,
metadataPath: metadataFile.path,
asset: asset,
location: geoLocation.position)));
location: geoLocation.position,
shareCode: widget.payload.shareCode)));
},
color: AppColor.momaGreen,
),
Expand All @@ -295,9 +296,11 @@ class _HandSignaturePageState extends State<HandSignaturePage> {
class HandSignaturePayload {
final Uint8List image;
final AssetToken asset;
final String? shareCode;

HandSignaturePayload(
this.image,
this.asset,
this.shareCode,
);
}
88 changes: 81 additions & 7 deletions lib/screen/interactive_postcard/postcard_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,71 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
);
}

Future<void> _showSharingExpired(BuildContext context) async {
await UIHelper.showPostcardDrawerAction(context, options: [
OptionItem(
builder: (context, _) => Row(
children: [
const SizedBox(width: 15),
SizedBox(
width: 30,
child: SvgPicture.asset(
'assets/images/restart.svg',
width: 24,
height: 24,
),
),
const SizedBox(width: 18),
Expanded(
child: Text(
'you_need_resend'.tr(),
style: Theme.of(context).textTheme.moMASans700Black18,
),
),
],
),
),
OptionItem(
builder: (context, _) => Row(
children: [
const SizedBox(width: 15),
SvgPicture.asset(
'assets/images/arrow_right.svg',
width: 24,
height: 24,
),
const SizedBox(width: 18),
Expanded(
child: Text(
'no_one_received'.tr(),
style: Theme.of(context).textTheme.moMASans700AuGrey18,
),
),
],
),
),
OptionItem(
builder: (context, _) => Row(
children: [
const SizedBox(width: 15),
SvgPicture.asset(
'assets/images/cross.svg',
width: 24,
height: 24,
),
const SizedBox(width: 18),
Expanded(
child: Text(
'resend_new_link'.tr(),
style: Theme.of(context).textTheme.moMASans700AuGrey18,
),
),
],
),
)
]);
}

Future<void> _removeShareConfig(AssetToken assetToken) async {
await _configurationService.removeSharedPostcardWhere(
(p) => p.owner == assetToken.owner && p.tokenID == assetToken.id);
Expand Down Expand Up @@ -384,6 +449,15 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
if (assetToken.didSendNext) {
unawaited(_removeShareConfig(assetToken));
}

if (assetToken.isShareExpired &&
(assetToken.isLastOwner && !isViewOnly)) {
if (!mounted) {
return;
}
unawaited(_showSharingExpired(context));
unawaited(_removeShareConfig(assetToken));
}
}
if (!mounted) {
return;
Expand Down Expand Up @@ -644,28 +718,28 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
);
}
if (!(asset.isStamping || asset.isStamped || asset.isProcessingStamp)) {
return PostcardButton(
return PostcardAsyncButton(
text: 'stamp_postcard'.tr(),
onTap: () async {
if (asset.numberOwners > 1) {
final button = PostcardAsyncButton(
text: 'continue'.tr(),
fontSize: 18,
onTap: () async {
unawaited(injector<NavigationService>().popAndPushNamed(
await injector<NavigationService>().popAndPushNamed(
AppRouter.designStamp,
arguments: DesignStampPayload(asset, false)));
arguments: DesignStampPayload(asset, false, null));
},
color: AppColor.momaGreen,
);
final page = _postcardPreview(context, asset);
unawaited(Navigator.of(context).pushNamed(
await Navigator.of(context).pushNamed(
AppRouter.postcardExplain,
arguments: PostcardExplainPayload(asset, button, pages: [page]),
));
);
} else {
unawaited(injector<NavigationService>()
.selectPromptsThenStamp(context, asset));
await injector<NavigationService>()
.selectPromptsThenStamp(context, asset, null);
}
},
color: MoMAColors.moMA8,
Expand Down
1 change: 1 addition & 0 deletions lib/screen/interactive_postcard/postcard_explain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ class _PostcardExplainState extends State<PostcardExplain> {
postcardAspectRatio,
child: PostcardViewWidget(
assetToken: asset,
withPreviewStamp: true,
),
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/screen/interactive_postcard/prompt_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ class _PromptPageState extends State<PromptPage> {
Prompt.getUserPrompt(_controller.text.trim()));
await Navigator.of(context).pushNamed(
AppRouter.designStamp,
arguments:
DesignStampPayload(assetWithPrompt, true));
arguments: DesignStampPayload(assetWithPrompt, true,
widget.payload.shareCode));
},
)),
Flexible(
Expand Down
Loading

0 comments on commit 2042d41

Please sign in to comment.