Skip to content

Commit

Permalink
Return to sender
Browse files Browse the repository at this point in the history
  • Loading branch information
ppupha committed Dec 7, 2023
1 parent 5baa389 commit b3d9ba6
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 103 deletions.
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,
);
}
4 changes: 2 additions & 2 deletions lib/screen/interactive_postcard/postcard_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
onTap: () async {
unawaited(injector<NavigationService>().popAndPushNamed(
AppRouter.designStamp,
arguments: DesignStampPayload(asset, false)));
arguments: DesignStampPayload(asset, false, null)));
},
color: AppColor.momaGreen,
);
Expand All @@ -665,7 +665,7 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
));
} else {
unawaited(injector<NavigationService>()
.selectPromptsThenStamp(context, asset));
.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 @@ -448,6 +448,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
40 changes: 25 additions & 15 deletions lib/screen/interactive_postcard/stamp_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,31 @@ class _StampPreviewState extends State<StampPreview> with AfterLayoutMixin {
setState(() {
confirming = true;
});
await _postcardService
.finalizeStamp(widget.payload.asset, widget.payload.imagePath,
widget.payload.metadataPath, widget.payload.location)
.then((final bool isStampSuccess) async {
_setTimer();
if (mounted) {
setState(() {
confirming = false;
});
if (!isStampSuccess) {
await UIHelper.showPostcardStampFailed(context);
}
try {
await _postcardService
.finalizeStamp(
asset: widget.payload.asset,
imagePath: widget.payload.imagePath,
metadataPath: widget.payload.metadataPath,
location: widget.payload.location,
shareCode: widget.payload.shareCode)
.then((final bool isStampSuccess) async {
_setTimer();
if (mounted) {
_onClose(context);
setState(() {
confirming = false;
});
if (!isStampSuccess) {
await UIHelper.showPostcardStampFailed(context);
}
if (mounted) {
_onClose(context);
}
}
}
});
});
} catch (e) {
log.info(e);
}
}

void _onClose(BuildContext context) {
Expand Down Expand Up @@ -200,13 +208,15 @@ class StampPreviewPayload {
final String imagePath;
final String metadataPath;
final Location location;
final String? shareCode;

// constructor
StampPreviewPayload({
required this.asset,
required this.imagePath,
required this.metadataPath,
required this.location,
required this.shareCode,
});
}

Expand Down
66 changes: 24 additions & 42 deletions lib/screen/send_receive_postcard/receive_postcard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import 'package:autonomy_flutter/service/navigation_service.dart';
import 'package:autonomy_flutter/service/postcard_service.dart';
import 'package:autonomy_flutter/util/asset_token_ext.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/ui_helper.dart';
import 'package:autonomy_flutter/util/wallet_utils.dart';
import 'package:autonomy_flutter/view/postcard_button.dart';
import 'package:dio/dio.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -42,6 +40,8 @@ class ReceivePostCardPage extends StatefulWidget {
class _ReceivePostCardPageState extends State<ReceivePostCardPage> {
final metricClient = injector.get<MetricClientService>();
final tokenService = injector.get<TokensService>();
final accountService = injector<AccountService>();
final postcardService = injector<PostcardService>();
late bool _isProcessing;
late bool _isConfirming;
late AssetToken assetToken;
Expand Down Expand Up @@ -103,13 +103,9 @@ class _ReceivePostCardPageState extends State<ReceivePostCardPage> {
}
}

Future<AssetToken?> _receivePostcard(
BuildContext context, AssetToken asset) async {
final geoLocation = internetUserGeoLocation;
final accountService = injector<AccountService>();
final addresses = await accountService.getAddress(asset.blockchain);
Future<String?> _getAddress(String blockchain) async {
final addresses = await accountService.getAddress(blockchain);
String? address;
AssetToken? pendingToken;
if (addresses.isEmpty) {
final defaultPersona = await accountService.getOrCreateDefaultPersona();
final walletAddress =
Expand All @@ -133,42 +129,28 @@ class _ReceivePostCardPageState extends State<ReceivePostCardPage> {
},
);
}
return address;
}

Future<AssetToken?> _receivePostcard(
BuildContext context, AssetToken asset) async {
AssetToken? pendingToken;
final address = await _getAddress(asset.blockchain);
if (address != null) {
try {
pendingToken =
await injector.get<PostcardService>().claimSharedPostcardToAddress(
address: address,
assetToken: asset,
location: geoLocation.position,
shareCode: widget.shareCode,
);
if (!mounted) {
return null;
}
unawaited(Navigator.of(context).pushNamedAndRemoveUntil(
AppRouter.homePage,
(route) => false,
));
unawaited(Navigator.of(context).pushNamed(AppRouter.designStamp,
arguments: DesignStampPayload(pendingToken, false)));
} catch (e) {
if (e is DioException) {
if (!mounted) {
return null;
}
await UIHelper.showAlreadyClaimedPostcard(
context,
e,
);
if (!mounted) {
return null;
}
unawaited(Navigator.of(context).pushNamedAndRemoveUntil(
AppRouter.homePage,
(route) => false,
));
}
pendingToken = postcardService.getPendingTokenAfterClaimShare(
address: address,
assetToken: asset,
);
if (!mounted) {
return null;
}
unawaited(Navigator.of(context).pushNamedAndRemoveUntil(
AppRouter.homePage,
(route) => false,
));
unawaited(Navigator.of(context).pushNamed(AppRouter.designStamp,
arguments:
DesignStampPayload(pendingToken, false, widget.shareCode)));
}
setState(() {
_isProcessing = false;
Expand Down
10 changes: 4 additions & 6 deletions lib/service/navigation_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ import 'package:autonomy_flutter/util/ui_helper.dart';
import 'package:autonomy_theme/autonomy_theme.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:nft_collection/models/asset_token.dart';

// ignore: implementation_imports
import 'package:nft_collection/models/asset_token.dart'; // ignore: implementation_imports
import 'package:overlay_support/src/overlay_state_finder.dart';

class NavigationService {
Expand Down Expand Up @@ -86,19 +84,19 @@ class NavigationService {
}

Future<void> selectPromptsThenStamp(
BuildContext context, AssetToken asset) async {
BuildContext context, AssetToken asset, String? shareCode) async {
final prompts =
await injector<PostcardService>().getPrompts(asset.tokenId!);
if (!mounted) {
return;
}
if (prompts.isEmpty) {
await popAndPushNamed(AppRouter.promptPage,
arguments: DesignStampPayload(asset, true));
arguments: DesignStampPayload(asset, true, shareCode));
} else {
final assetWithPrompt = asset.setAssetPrompt(prompts.first);
await popAndPushNamed(AppRouter.designStamp,
arguments: DesignStampPayload(assetWithPrompt, true));
arguments: DesignStampPayload(assetWithPrompt, true, shareCode));
}
}

Expand Down
Loading

0 comments on commit b3d9ba6

Please sign in to comment.