Skip to content

Commit

Permalink
Merge branch 'develop' into Sang/postcard/stamping_faster
Browse files Browse the repository at this point in the history
  • Loading branch information
ppupha committed Oct 25, 2023
2 parents 060edeb + 6b29ef7 commit a82e97b
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 87 deletions.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/screen/detail/artwork_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import 'package:json_annotation/json_annotation.dart';
import 'package:nft_collection/models/asset_token.dart';
import 'package:nft_collection/models/provenance.dart';
import 'package:nft_collection/nft_collection.dart';
import 'package:share/share.dart';
import 'package:share_plus/share_plus.dart';
import 'package:social_share/social_share.dart';
import 'package:url_launcher/url_launcher.dart';

Expand Down
15 changes: 6 additions & 9 deletions lib/screen/github_doc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
// that can be found in the LICENSE file.
//

import 'package:autonomy_flutter/screen/app_router.dart';
import 'package:autonomy_flutter/common/injector.dart';
import 'package:autonomy_flutter/service/navigation_service.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/dio_interceptors.dart';
import 'package:autonomy_flutter/util/dio_util.dart';
import 'package:autonomy_flutter/util/string_ext.dart';
import 'package:autonomy_flutter/util/style.dart';
import 'package:autonomy_flutter/view/back_appbar.dart';
import 'package:autonomy_flutter/view/responsive.dart';
Expand All @@ -32,6 +34,7 @@ class GithubDocPage extends StatefulWidget {
class _GithubDocPageState extends State<GithubDocPage> {
late String document;
late String title;
final _navigationService = injector<NavigationService>();

final dio = baseDio(BaseOptions(
baseUrl: "https://raw.githubusercontent.com",
Expand Down Expand Up @@ -83,14 +86,8 @@ class _GithubDocPageState extends State<GithubDocPage> {
styleSheet: markDownLightStyle(context),
onTapLink: (text, href, title) async {
if (href == null) return;
if (!(await canLaunchUrlString(href))) {
if (!mounted) return;
Navigator.of(context).pushNamed(AppRouter.githubDocPage,
arguments: {
"prefix": widget.payload["prefix"] ?? '',
"document": href,
"title": ""
});
if (href.isAutonomyDocumentLink) {
_navigationService.openAutonomyDocument(href, title);
} else {
launchUrlString(href);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/screen/global_receive/receive_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_vibrate/flutter_vibrate.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:share/share.dart';
import 'package:share_plus/share_plus.dart';

class GlobalReceiveDetailPage extends StatefulWidget {
static const tag = "global_receive_detail";
Expand Down
13 changes: 1 addition & 12 deletions lib/screen/interactive_postcard/design_stamp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,7 @@ class _DesignStampPageState extends State<DesignStampPage> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 80),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"all_cells_must_be_filled".tr(),
style: theme.textTheme.moMASans400Grey12
.copyWith(color: AppColor.auQuickSilver),
),
],
),
const SizedBox(height: 16),
const SizedBox(height: 96),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
Expand Down
26 changes: 17 additions & 9 deletions lib/screen/interactive_postcard/postcard_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import 'package:nft_collection/models/asset_token.dart';
import 'package:nft_collection/models/provenance.dart';
import 'package:nft_collection/widgets/nft_collection_bloc.dart';
import 'package:nft_collection/widgets/nft_collection_bloc_event.dart';
import 'package:share/share.dart';
import 'package:share_plus/share_plus.dart';

class PostcardDetailPagePayload extends ArtworkDetailPayload {
final bool isFromLeaderboard;
Expand Down Expand Up @@ -624,10 +624,12 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
PostcardAsyncButton(
text: "invite_to_collaborate".tr(),
onTap: () async {
await _sharePostcard(context, asset);
setState(() {
isSending = state.isSending();
});
final shareResult = await _sharePostcard(context, asset);
if (shareResult?.status == ShareResultStatus.success) {
setState(() {
isSending = state.isSending();
});
}
},
),
...sendPostcardExplain,
Expand All @@ -648,25 +650,31 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
}
}

Future<void> _sharePostcard(BuildContext context, AssetToken asset) async {
Future<ShareResult?> _sharePostcard(
BuildContext context, AssetToken asset) async {
try {
final shareTime = DateTime.now();
final sharePostcardResponse = await _postcardService.sharePostcard(asset);
if (sharePostcardResponse.deeplink?.isNotEmpty ?? false) {
final shareMessage = "postcard_share_message".tr(namedArgs: {
'deeplink': sharePostcardResponse.deeplink!,
});
Share.share(shareMessage);
final result = await Share.shareWithResult(shareMessage);
if (result.status == ShareResultStatus.success) {
await Future.delayed(const Duration(milliseconds: 100));
await _configurationService.updateSharedPostcard(
[SharedPostcard(asset.id, asset.owner, shareTime)]);
}
return result;
}
_configurationService.updateSharedPostcard(
[SharedPostcard(asset.id, asset.owner, shareTime)]);
} catch (e) {
if (e is DioException) {
if (mounted) {
UIHelper.showSharePostcardFailed(context, e);
}
}
}
return null;
}

Widget _postcardInfo(BuildContext context, PostcardDetailState state) {
Expand Down
20 changes: 11 additions & 9 deletions lib/screen/interactive_postcard/postcard_explain.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:autonomy_flutter/common/injector.dart';
import 'package:autonomy_flutter/service/configuration_service.dart';
import 'package:autonomy_flutter/service/navigation_service.dart';
import 'package:autonomy_flutter/service/postcard_service.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/distance_formater.dart';
Expand All @@ -14,7 +15,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/svg.dart';
import 'package:nft_collection/models/asset_token.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:video_player/video_player.dart';

class PostcardExplain extends StatefulWidget {
Expand All @@ -28,6 +28,7 @@ class PostcardExplain extends StatefulWidget {
}

class _PostcardExplainState extends State<PostcardExplain> {
final _navigationService = injector<NavigationService>();
final VideoPlayerController _controller =
VideoPlayerController.asset("assets/videos/postcard_explain.mp4");
final VideoPlayerController _colouringController =
Expand Down Expand Up @@ -224,14 +225,15 @@ class _PostcardExplainState extends State<PostcardExplain> {
text: "by_continuing".tr(),
),
TextSpan(
text: "terms_and_conditions".tr(),
style: termsConditionsStyle.copyWith(
decoration: TextDecoration.underline),
recognizer: TapGestureRecognizer()
..onTap = () => launchUrl(
Uri.parse(MOMA_TERMS_CONDITIONS_URL),
mode: LaunchMode.externalApplication),
),
text: "terms_and_conditions".tr(),
style: termsConditionsStyle.copyWith(
decoration: TextDecoration.underline),
recognizer: TapGestureRecognizer()
..onTap = () {
_navigationService.openAutonomyDocument(
MOMA_TERMS_CONDITIONS_URL,
"terms_and_conditions".tr());
}),
const TextSpan(
text: ".",
),
Expand Down
5 changes: 0 additions & 5 deletions lib/screen/onboarding/import_address/import_seeds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ class _ImportSeedsPageState extends State<ImportSeedsPage> {
final TextEditingController _phraseTextController = TextEditingController();
bool _isSubmissionEnabled = false;

@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down
6 changes: 3 additions & 3 deletions lib/service/customer_support_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ class CustomerSupportServiceImpl extends CustomerSupportService {
final version = (await PackageInfo.fromPlatform()).version;
mutedMessage += "**Version**: $version\n";

final device = DeviceInfo.instance;
String deviceName = await device.getMachineName() ?? "N/A";
mutedMessage += "**DeviceName**: $deviceName\n";
final deviceInfo = await DeviceInfo.instance.getUserDeviceInfo();
mutedMessage += "**DeviceName**: ${deviceInfo.machineName}\n";
mutedMessage += "**OSVersion**: ${deviceInfo.oSVersion}\n";

for (var mutedMsg in (mutedText ?? [])) {
mutedMessage += "$mutedMsg\n";
Expand Down
21 changes: 18 additions & 3 deletions lib/service/navigation_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/error_handler.dart';
import 'package:autonomy_flutter/util/inapp_notifications.dart';
import 'package:autonomy_flutter/util/log.dart';
import 'package:autonomy_flutter/util/string_ext.dart';
import 'package:autonomy_flutter/util/style.dart';
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';

Check notice on line 30 in lib/service/navigation_service.dart

View workflow job for this annotation

GitHub Actions / lint the dart code

Import of a library in the 'lib/src' directory of another package.

Try importing a public library that exports this library, or removing the import. See https://dart.dev/lints/implementation_imports to learn more about this problem.

class NavigationService {
Expand Down Expand Up @@ -361,4 +360,20 @@ class NavigationService {
await UIHelper.showPostcardQRExpired(navigatorKey.currentContext!);
}
}

Future<void> openAutonomyDocument(String href, String title) async {
if (navigatorKey.currentContext != null &&
navigatorKey.currentState?.mounted == true) {
final uri = Uri.parse(href.autonomyRawDocumentLink);
final document = uri.pathSegments.last;
final prefix =
uri.pathSegments.sublist(0, uri.pathSegments.length - 1).join("/");
await Navigator.of(navigatorKey.currentContext!)
.pushNamed(AppRouter.githubDocPage, arguments: {
"prefix": "/$prefix/",
"document": document,
"title": title,
});
}
}
}
5 changes: 3 additions & 2 deletions lib/service/pending_token_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,19 @@ extension FilterEventExt on FilterEvent {
}

AssetToken? toAssetToken(String owner, DateTime timestamp) {
String? contractType;
String? contractType, toAddressStr;
BigInt? tokenId;

if (isErc1155()) {
contractType = "erc1155";
tokenId = getERC1155TokenId();
toAddressStr = topics![3]?.substring(26);
} else if (isERC721()) {
contractType = "erc721";
tokenId = getERC721TokenId();
toAddressStr = topics![2]?.substring(26);
}

final toAddressStr = topics![2]?.substring(26);
if (toAddressStr == null) {
return null;
}
Expand Down
21 changes: 0 additions & 21 deletions lib/service/postcard_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import 'package:nft_collection/services/tokens_service.dart';
import 'package:nft_collection/widgets/nft_collection_bloc.dart';
import 'package:nft_collection/widgets/nft_collection_bloc_event.dart';
import 'package:path_provider/path_provider.dart';
import 'package:share/share.dart';

import 'account_service.dart';

Expand Down Expand Up @@ -104,12 +103,6 @@ abstract class PostcardService {

Future<void> downloadPostcard(String tokenId);

Future<void> shareStampToTwitter({
required String tokenId,
required int stampIndex,
String caption = "",
});

String getTokenId(String id);

Future<AssetToken> claimEmptyPostcardToAddress(
Expand Down Expand Up @@ -495,20 +488,6 @@ class PostcardServiceImpl extends PostcardService {
await imageFile.delete();
}

@override
Future<void> shareStampToTwitter({
required String tokenId,
required int stampIndex,
String caption = "",
}) async {
final imageFile =
await _downloadStamp(tokenId: tokenId, stampIndex: stampIndex);
Share.shareFiles(
[imageFile.path],
text: caption,
);
}

@override
String getTokenId(String id) {
return "tez-${Environment.postcardContractAddress}-$id";
Expand Down
7 changes: 7 additions & 0 deletions lib/util/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ const TV_APP_STORE_URL =
const MOMA_TERMS_CONDITIONS_URL =
"https://github.com/bitmark-inc/autonomy-apps/blob/main/docs/postcard_terms.md";

const AUTONOMY_DOCUMENT_PREFIX = "https://github.com/bitmark-inc";

const AUTONOMY_RAW_DOCUMENT_PREFIX =
"https://raw.githubusercontent.com/bitmark-inc";

const MARKDOWN_EXT = ".md";

const String POSTCARD_SIGN_PREFIX = "Tezos Signed Message:";

const CONNECT_FAILED_DURATION = Duration(seconds: 10);
Expand Down
7 changes: 5 additions & 2 deletions lib/util/http_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ class HttpHelper {
"Content-Type": "application/json",
});

final response =
await http.post(url, headers: headers, body: jsonEncode(body));
final response = await http.post(
url,
headers: headers,
body: body != null ? jsonEncode(body) : null,
);
return response;
}
}
12 changes: 12 additions & 0 deletions lib/util/string_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import 'package:autonomy_flutter/common/environment.dart';
import 'package:autonomy_flutter/util/constants.dart';

extension StringExtension on String {
String capitalize() {
Expand Down Expand Up @@ -82,4 +83,15 @@ extension StringExtension on String {
return splitted.length > 1 &&
splitted[1] == Environment.postcardContractAddress;
}

bool get isAutonomyDocumentLink {
return (startsWith(AUTONOMY_DOCUMENT_PREFIX) ||
startsWith(AUTONOMY_RAW_DOCUMENT_PREFIX)) &&
endsWith(MARKDOWN_EXT);
}

String get autonomyRawDocumentLink {
return replaceFirst(AUTONOMY_DOCUMENT_PREFIX, AUTONOMY_RAW_DOCUMENT_PREFIX)
.replaceFirst("/blob/", "/");
}
}
2 changes: 1 addition & 1 deletion lib/util/ui_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_vibrate/flutter_vibrate.dart';
import 'package:jiffy/jiffy.dart';
import 'package:share/share.dart';
import 'package:share_plus/share_plus.dart';

enum ActionState { notRequested, loading, error, done }

Expand Down
10 changes: 8 additions & 2 deletions lib/view/artwork_common_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:autonomy_flutter/service/configuration_service.dart';
import 'package:autonomy_flutter/service/customer_support_service.dart';
import 'package:autonomy_flutter/service/feralfile_service.dart';
import 'package:autonomy_flutter/service/metric_client_service.dart';
import 'package:autonomy_flutter/service/navigation_service.dart';
import 'package:autonomy_flutter/util/address_utils.dart';
import 'package:autonomy_flutter/util/asset_token_ext.dart';
import 'package:autonomy_flutter/util/au_icons.dart';
Expand Down Expand Up @@ -1864,8 +1865,13 @@ class _PostcardRightsViewState extends State<PostcardRightsView> {
styleSheet: markDownPostcardRightStyle(context),
onTapLink: (text, href, title) async {
if (href == null) return;
launchUrl(Uri.parse(href),
mode: LaunchMode.externalApplication);
if (href.isAutonomyDocumentLink) {
injector<NavigationService>()
.openAutonomyDocument(href, text);
} else {
launchUrl(Uri.parse(href),
mode: LaunchMode.externalApplication);
}
},
),
const SizedBox(height: 23.0),
Expand Down
Loading

0 comments on commit a82e97b

Please sign in to comment.