Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove support instant purchase #2327

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/common/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ Future<void> setupInjector() async {
injector
.registerLazySingleton<UserAccountChannel>(() => UserAccountChannel());

injector.registerLazySingleton<AddressService>(
() => AddressService(injector(), injector()));
injector
.registerLazySingleton<AddressService>(() => AddressService(injector()));

injector.registerLazySingleton<KeychainService>(() => KeychainService());

Expand Down
50 changes: 0 additions & 50 deletions lib/screen/irl_screen/webview_irl_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import 'package:autonomy_flutter/service/auth_service.dart';
import 'package:autonomy_flutter/service/configuration_service.dart';
import 'package:autonomy_flutter/service/customer_support_service.dart';
import 'package:autonomy_flutter/service/navigation_service.dart';
import 'package:autonomy_flutter/util/asset_token_ext.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/exception.dart';
import 'package:autonomy_flutter/util/log.dart';
Expand All @@ -29,10 +28,6 @@ import 'package:autonomy_flutter/view/select_address.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:nft_collection/graphql/model/get_list_tokens.dart';
import 'package:nft_collection/nft_collection.dart';
import 'package:nft_collection/services/indexer_service.dart';
import 'package:nft_collection/services/tokens_service.dart';
import 'package:tezart/tezart.dart';
import 'package:uuid/uuid.dart';
import 'package:walletconnect_flutter_v2/apis/core/pairing/utils/pairing_models.dart';
Expand Down Expand Up @@ -259,51 +254,6 @@ class _IRLWebScreenState extends State<IRLWebScreen> {
}
Navigator.of(context).pop(response);

return;
case 'instant_purchase':
final data = argument['data'] as Map<String, dynamic>;
final shouldClose = data['close'] as bool;
log.info('[IRLWebScreen] handle instantPurchase close= $shouldClose:');
try {
final tokenIdsDynamic = data['token_ids'] as List<dynamic>? ?? [];
final tokenIds = tokenIdsDynamic.map((e) => e.toString()).toList();
final address = data['address'];
final isNonCryptoPayment = data['is_non_crypto_payment'] as bool;
if (tokenIds.isNotEmpty && address != null && isNonCryptoPayment) {
final indexerService = injector<IndexerService>();
final tokens =
await indexerService.getNftTokens(QueryListTokensRequest(
ids: tokenIds,
));
final pendingTokens = tokens
.map((e) => e.copyWith(
pending: true,
owner: address,
owners: {address: 1},
isManual: false,
lastActivityTime: DateTime.now(),
lastRefreshedTime: DateTime(1),
balance: 1,
))
.toList();
log.info('[IRLWebScreen] instant_purchase : ${pendingTokens.length}'
' pending tokens');
await injector<TokensService>().setCustomTokens(pendingTokens);
unawaited(injector<TokensService>().reindexAddresses([address]));
if (pendingTokens.isNotEmpty) {
NftCollectionBloc.eventController
.add(UpdateTokensEvent(tokens: pendingTokens));
}
}
} catch (e) {
log.info('[IRLWebScreen] instant_purchase error while set'
' pending token : $e');
}

if (shouldClose) {
log.info('[IRLWebScreen] instantPurchase finish and close ');
unawaited(injector<NavigationService>().popToCollection());
}
return;
default:
return;
Expand Down
33 changes: 1 addition & 32 deletions lib/service/address_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import 'dart:async';
import 'dart:convert';

import 'package:autonomy_flutter/common/injector.dart';
import 'package:autonomy_flutter/database/entity/wallet_address.dart';
import 'package:autonomy_flutter/graphql/account_settings/cloud_manager.dart';
import 'package:autonomy_flutter/service/auth_service.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/log.dart';
import 'package:autonomy_flutter/util/user_account_channel.dart';
import 'package:autonomy_flutter/util/wallet_storage_ext.dart';
Expand All @@ -21,9 +18,8 @@ import 'package:sentry/sentry.dart';

class AddressService {
final UserAccountChannel _primaryAddressChannel;
final CloudManager _cloudObject;

AddressService(this._primaryAddressChannel, this._cloudObject);
AddressService(this._primaryAddressChannel);

Future<AddressInfo?> getPrimaryAddressInfo() async =>
await _primaryAddressChannel.getPrimaryAddress();
Expand Down Expand Up @@ -127,31 +123,4 @@ class AddressService {
'type': 'ethereum',
};
}

Future<List<WalletAddress>> getAllAddress() async {
final addresses = _cloudObject.addressObject.getAllAddresses();
return addresses;
}

List<WalletAddress> getAllEthereumAddress() {
final addresses = _cloudObject.addressObject
.getAddressesByType(CryptoType.ETH.source)
..sort((a, b) => a.createdAt.compareTo(b.createdAt));
return addresses;
}

AddressInfo pickAddressAsPrimary() {
log.info('[AddressService] Picking address as primary');
final ethAddresses = getAllEthereumAddress();
if (ethAddresses.isEmpty) {
log.info('[AddressService] No address found');
throw UnsupportedError('No address found');
}
final selectedAddress = ethAddresses.first;
log.info('[AddressService] Selected address: $selectedAddress');
return AddressInfo(
uuid: selectedAddress.uuid,
index: selectedAddress.index,
chain: selectedAddress.cryptoType.toLowerCase());
}
}
59 changes: 0 additions & 59 deletions lib/service/deeplink_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -468,65 +468,6 @@ class DeeplinkServiceImpl extends DeeplinkService {
}
}

case 'InstantPurchase':
final url = data['callback_url'];
final expiredAt = data['expired_at'];
if (expiredAt != null) {
final expiredAtDate =
DateTime.fromMillisecondsSinceEpoch(int.tryParse(expiredAt) ?? 0);
if (expiredAtDate.isBefore(DateTime.now())) {
unawaited(_navigationService.showQRExpired());
break;
}
}
final instantToken = data['instant_purchase_token'];
final purchaseToken = data['purchase_token'];
if (url != null &&
data['chain'] != null &&
instantToken != null &&
purchaseToken != null) {
final chain = data['chain'].toString().toLowerCase();
late String? primaryAddress;
final addressService = injector<AddressService>();
try {
final primaryAddressInfo =
await addressService.getPrimaryAddressInfo();
if (primaryAddressInfo != null &&
primaryAddressInfo.chain == chain) {
log.info(
'[DeeplinkService] InstancePurchase: primary address found');
primaryAddress =
await addressService.getAddress(info: primaryAddressInfo);
} else {
log.info('[DeeplinkService] '
'InstancePurchase: use address with most tokens');
final addressWallets = await addressService.getAllAddress();
addressWallets.removeWhere(
(element) => element.cryptoType.toLowerCase() != chain);
if (addressWallets.isEmpty) {
primaryAddress = null;
} else {
primaryAddress = addressWallets.first.address;
}
}
} catch (e) {
log.info('[DeeplinkService] get primary address error $e');
primaryAddress = null;
}
_navigationService.popUntilHome();
if (primaryAddress == null) {
await _navigationService.addressNotFoundError();
} else {
final link =
'$url&ba=$primaryAddress&ipt=$instantToken&pt=$purchaseToken';
log.info('InstantPurchase: $link');
await _navigationService.goToIRLWebview(IRLWebScreenPayload(link,
isPlainUI: true,
statusBarColor: AppColor.white,
isDarkStatusBar: false));
}
}

case 'membership_subscription':
final String url = data['callbackURL']!;
final primaryAddress =
Expand Down
9 changes: 0 additions & 9 deletions lib/service/navigation_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,6 @@ class NavigationService {
}
}

Future<void> showQRExpired() async {
if (navigatorKey.currentContext != null &&
navigatorKey.currentState?.mounted == true) {
await UIHelper.showInfoDialog(
context, 'qr_code_expired'.tr(), 'qr_code_expired_desc'.tr(),
onClose: () => UIHelper.hideInfoDialog(context), isDismissible: true);
}
}

Future<void> addressNotFoundError() async {
if (navigatorKey.currentContext != null &&
navigatorKey.currentState?.mounted == true) {
Expand Down
9 changes: 0 additions & 9 deletions test/generate_mock/service/mock_navigation_service.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,6 @@ class MockNavigationService extends _i2.Mock implements _i3.NavigationService {
returnValueForMissingStub: _i4.Future<void>.value(),
) as _i4.Future<void>);
@override
_i4.Future<void> showQRExpired() => (super.noSuchMethod(
Invocation.method(
#showQRExpired,
[],
),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value(),
) as _i4.Future<void>);
@override
_i4.Future<void> addressNotFoundError() => (super.noSuchMethod(
Invocation.method(
#addressNotFoundError,
Expand Down
Loading