Skip to content

Commit

Permalink
merchandise support
Browse files Browse the repository at this point in the history
Signed-off-by: phuoc <[email protected]>
  • Loading branch information
phuocbitmark committed Oct 24, 2023
1 parent 6b29ef7 commit c77e321
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 9 deletions.
2 changes: 1 addition & 1 deletion assets
41 changes: 36 additions & 5 deletions lib/screen/interactive_postcard/postcard_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import 'package:autonomy_flutter/screen/interactive_postcard/postcard_view_widge
import 'package:autonomy_flutter/screen/interactive_postcard/travel_info/postcard_travel_info.dart';
import 'package:autonomy_flutter/screen/interactive_postcard/travel_info/travel_info_bloc.dart';
import 'package:autonomy_flutter/screen/interactive_postcard/travel_info/travel_info_state.dart';
import 'package:autonomy_flutter/screen/irl_screen/webview_irl_screen.dart';
import 'package:autonomy_flutter/screen/settings/help_us/inapp_webview.dart';
import 'package:autonomy_flutter/service/auth_service.dart';
import 'package:autonomy_flutter/service/chat_service.dart';
import 'package:autonomy_flutter/service/configuration_service.dart';
import 'package:autonomy_flutter/service/metric_client_service.dart';
Expand Down Expand Up @@ -540,9 +542,7 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
),
if (!isViewOnly) ...[
_postcardAction(context, state),
const SizedBox(
height: 20,
),
const SizedBox(height: 20),
],
_postcardInfo(context, state),
const SizedBox(
Expand Down Expand Up @@ -593,8 +593,10 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
Widget _postcardAction(BuildContext context, PostcardDetailState state) {
final asset = state.assetToken!;
final theme = Theme.of(context);
if (asset.isCompleted ||
!state.isLastOwner ||
if (asset.isCompleted && !isViewOnly) {
return _postcardPhysical(context, state);
}
if (!state.isLastOwner ||
!state.postcardValueLoaded ||
isViewOnly != false) {
return const SizedBox();
Expand Down Expand Up @@ -671,6 +673,35 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
}
}

Widget _postcardPhysical(BuildContext context, PostcardDetailState state) {
return Column(
children: [
PostcardButton(
text: "unlock_physical_objects".tr(),
color: POSTCARD_PINK_BUTTON_COLOR,
onTap: () async {
final indexId = state.assetToken!.id;
final jwtToken =
(await injector<AuthService>().getAuthToken()).jwtToken;
final hasCustomerSupport =
_configurationService.hasMerchandiseSupport(indexId);
log.info("?indexId=$indexId&hasCS=$hasCustomerSupport");
if (!context.mounted) return;
final url =
"$AUTONOMY_MERCHANDISE_BASE_URL/?indexId=$indexId&hasCS=${hasCustomerSupport.toString()}&token=$jwtToken";
Navigator.of(context).pushNamed(AppRouter.irlWebView,
arguments: IRLWebScreenPayload(url, isPlainUI: true));
},
),
const SizedBox(height: 15),
Text(
"unlock_physical_objects_desc".tr(),
style: Theme.of(context).textTheme.moMASans400Black12,
),
],
);
}

Future<ShareResult?> _sharePostcard(
BuildContext context, AssetToken asset) async {
try {
Expand Down
51 changes: 51 additions & 0 deletions lib/screen/irl_screen/webview_irl_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'dart:convert';

import 'package:autonomy_flutter/common/injector.dart';
import 'package:autonomy_flutter/database/cloud_database.dart';
import 'package:autonomy_flutter/database/entity/draft_customer_support.dart';
import 'package:autonomy_flutter/model/connection_request_args.dart';
import 'package:autonomy_flutter/model/wc2_request.dart';
import 'package:autonomy_flutter/model/wc_ethereum_transaction.dart';
Expand All @@ -9,6 +12,8 @@ import 'package:autonomy_flutter/screen/settings/help_us/inapp_webview.dart';
import 'package:autonomy_flutter/screen/tezos_beacon/tb_send_transaction_page.dart';
import 'package:autonomy_flutter/screen/wallet_connect/send/wc_send_transaction_page.dart';
import 'package:autonomy_flutter/service/account_service.dart';
import 'package:autonomy_flutter/service/configuration_service.dart';
import 'package:autonomy_flutter/service/customer_support_service.dart';
import 'package:autonomy_flutter/service/metric_client_service.dart';
import 'package:autonomy_flutter/service/navigation_service.dart';
import 'package:autonomy_flutter/util/constants.dart';
Expand All @@ -24,6 +29,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:tezart/tezart.dart';
import 'package:uuid/uuid.dart';

class IRLWebScreen extends StatefulWidget {
final IRLWebScreenPayload payload;
Expand Down Expand Up @@ -131,6 +137,46 @@ class _IRLWebScreenState extends State<IRLWebScreen> {
}
}

Future<void> _receiveData(List<dynamic> args) async {
final argument = args.firstOrNull;
log.info('[IRLWebScreen] passData: $argument');
if (argument == null) {
return;
}
final type = argument['type'];
switch (type) {
case "customer_support":
final customerSupportService = injector<CustomerSupportService>();
final messageType = CSMessageType.CreateIssue.rawValue;
final issueID = "TEMP-${const Uuid().v4()}";
final data = argument['data'] as Map<String, dynamic>;
final title = data['title'];
final text = data['text'];
final orderId = data['orderId'];
final indexId = data['indexId'];
final draft = DraftCustomerSupport(
uuid: const Uuid().v4(),
issueID: issueID,
type: messageType,
data: json.encode(DraftCustomerSupportData(text: text, title: title)),
createdAt: DateTime.now(),
reportIssueType: ReportIssueType.MerchandiseIssue,
mutedMessages: [orderId, indexId].join("[SEPARATOR]"),
);

await customerSupportService.draftMessage(draft);
await injector<ConfigurationService>()
.setHasMerchandiseSupport(data['indexId']);
return;
case "open_customer_support":
if (!mounted) return;
Navigator.of(context).pushNamed(AppRouter.supportListPage);
return;
default:
return;
}
}

Future<JSResult?> _signMessage(List<dynamic> args) async {
try {
log.info('[IRLWebScreen] signMessage: $args');
Expand Down Expand Up @@ -317,6 +363,11 @@ class _IRLWebScreenState extends State<IRLWebScreen> {
callback: _getAddress,
);

_controller?.addJavaScriptHandler(
handlerName: 'passData',
callback: _receiveData,
);

_controller?.addJavaScriptHandler(
handlerName: 'signMessage',
callback: _signMessage,
Expand Down
35 changes: 35 additions & 0 deletions lib/service/configuration_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:uuid/uuid.dart';

abstract class ConfigurationService {
Future<void> setHasMerchandiseSupport(String indexId,
{bool value = true, bool isOverride = false});

bool hasMerchandiseSupport(String indexId);

Future<void> setPostcardChatConfig(PostcardChatConfig config);

PostcardChatConfig getPostcardChatConfig(
Expand Down Expand Up @@ -267,6 +272,8 @@ abstract class ConfigurationService {
}

class ConfigurationServiceImpl implements ConfigurationService {
static const String KEY_HAS_MERCHANDISE_SUPPORT_INDEX_ID =
"has_merchandise_support";
static const String KEY_POSTCARD_CHAT_CONFIG = "postcard_chat_config";
static const String KEY_DID_MIGRATE_ADDRESS = "did_migrate_address";
static const String KEY_HIDDEN_FEEDS = "hidden_feeds";
Expand Down Expand Up @@ -1197,4 +1204,32 @@ class ConfigurationServiceImpl implements ConfigurationService {
.toSet()
.toList());
}

@override
bool hasMerchandiseSupport(String indexId) {
final merchandiseSupportIndexIds =
_preferences.getStringList(KEY_HAS_MERCHANDISE_SUPPORT_INDEX_ID) ?? [];
return merchandiseSupportIndexIds.contains(indexId);
}

@override
Future<void> setHasMerchandiseSupport(String indexId,
{bool value = true, bool isOverride = false}) async {
if (isOverride) {
await _preferences
.setStringList(KEY_HAS_MERCHANDISE_SUPPORT_INDEX_ID, [indexId]);
} else {
final merchandiseSupportIndexIds =
_preferences.getStringList(KEY_HAS_MERCHANDISE_SUPPORT_INDEX_ID) ??
[];
if (value) {
merchandiseSupportIndexIds.add(indexId);
merchandiseSupportIndexIds.toSet().toList();
} else {
merchandiseSupportIndexIds.remove(indexId);
}
await _preferences.setStringList(
KEY_HAS_MERCHANDISE_SUPPORT_INDEX_ID, merchandiseSupportIndexIds);
}
}
}
20 changes: 17 additions & 3 deletions lib/util/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const DEEP_LINKS = [
const FF_ARTIST_COLLECTOR =
'https://feralfile.com/docs/artist-collector-rights';
const WEB3_PRIMER_URL = 'https://autonomy.io/catalog/primer/';
const AUTONOMY_MERCHANDISE_BASE_URL =
"http://192.168.31.162:3000"; //'https://autonomy.io/merchandise/';

const POSTCARD_RIGHTS_DOCS =
"https://raw.githubusercontent.com/bitmark-inc/autonomy-apps/main/docs/postcard_collector_rights.md";
Expand Down Expand Up @@ -120,6 +122,7 @@ const Duration SENT_ARTWORK_HIDE_TIME = Duration(minutes: 2);
const Duration STAMPING_POSTCARD_LIMIT_TIME = Duration(minutes: 60);

const Color POSTCARD_BACKGROUND_COLOR = Color.fromRGBO(242, 242, 242, 1);
const Color POSTCARD_PINK_BUTTON_COLOR = Color.fromRGBO(231, 75, 168, 1);

const POSTCARD_ABOUT_THE_PROJECT =
"https://www.moma.org/calendar/exhibitions/5618?preview=true";
Expand Down Expand Up @@ -265,9 +268,18 @@ class ReportIssueType {
static const Exception = 'exception';
static const ReportNFTIssue = 'report nft issue';
static const Announcement = 'announcement';

static List<String> get getList =>
[Feature, Bug, Feedback, Other, Exception, ReportNFTIssue, Announcement];
static const MerchandiseIssue = 'merchandise issue';

static List<String> get getList => [
Feature,
Bug,
Feedback,
Other,
Exception,
ReportNFTIssue,
Announcement,
MerchandiseIssue
];

static List<String> get getSuggestList => [Feature, Bug, Feedback, Other];

Expand All @@ -285,6 +297,8 @@ class ReportIssueType {
return 'Report NFT issue';
case Announcement:
return "Announcement";
case MerchandiseIssue:
return "Merchandise issue";
default:
return 'Something else?';
}
Expand Down

0 comments on commit c77e321

Please sign in to comment.