From e444a44f8bfd89116c4e28ff597fb0129ba7a298 Mon Sep 17 00:00:00 2001 From: ice-tychon <175587874+ice-tychon@users.noreply.github.com> Date: Fri, 24 Jan 2025 15:14:33 +0200 Subject: [PATCH] fix: Remove wallet from register complete request (#605) ## Description This PR prepares the app to move from TON to ION main wallet. Now our backend should specify the main wallet name and network. Also, for I speficied different endpoints for different wallet networks when we are creating a transaction to broadcast. ## Type of Change - [x] Bug fix - [ ] New feature - [ ] Breaking change - [ ] Refactoring - [ ] Documentation - [ ] Chore --- .../lib/src/auth/dtos/signed_challenge.c.dart | 24 +-- .../auth/dtos/signed_challenge.c.freezed.dart | 169 ++++++++++++++++++ .../src/auth/dtos/signed_challenge.c.g.dart | 14 +- .../lib/src/core/types/request_defaults.dart | 15 -- .../ton_transaction_creator.dart | 4 +- .../transaction_creator_factory.dart | 10 +- 6 files changed, 190 insertions(+), 46 deletions(-) create mode 100644 packages/ion_identity_client/lib/src/auth/dtos/signed_challenge.c.freezed.dart delete mode 100644 packages/ion_identity_client/lib/src/core/types/request_defaults.dart diff --git a/packages/ion_identity_client/lib/src/auth/dtos/signed_challenge.c.dart b/packages/ion_identity_client/lib/src/auth/dtos/signed_challenge.c.dart index 19bedddbaa..b2d00ce57c 100644 --- a/packages/ion_identity_client/lib/src/auth/dtos/signed_challenge.c.dart +++ b/packages/ion_identity_client/lib/src/auth/dtos/signed_challenge.c.dart @@ -1,27 +1,17 @@ // SPDX-License-Identifier: ice License 1.0 +import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:ion_identity_client/src/auth/dtos/dtos.dart'; -import 'package:ion_identity_client/src/core/types/request_defaults.dart'; import 'package:ion_identity_client/src/core/types/types.dart'; -import 'package:json_annotation/json_annotation.dart'; +part 'signed_challenge.c.freezed.dart'; part 'signed_challenge.c.g.dart'; -@JsonSerializable() -class SignedChallenge { - SignedChallenge({ - required this.firstFactorCredential, - this.wallets = RequestDefaults.registerCompleteWallets, - }); +@freezed +class SignedChallenge with _$SignedChallenge { + const factory SignedChallenge({ + required CredentialRequestData firstFactorCredential, + }) = _SignedChallenge; factory SignedChallenge.fromJson(JsonObject json) => _$SignedChallengeFromJson(json); - - final CredentialRequestData firstFactorCredential; - final List wallets; - - JsonObject toJson() => _$SignedChallengeToJson(this); - - @override - String toString() => - 'SignedChallenge(firstFactorCredential: $firstFactorCredential, wallets: $wallets)'; } diff --git a/packages/ion_identity_client/lib/src/auth/dtos/signed_challenge.c.freezed.dart b/packages/ion_identity_client/lib/src/auth/dtos/signed_challenge.c.freezed.dart new file mode 100644 index 0000000000..2e108e823c --- /dev/null +++ b/packages/ion_identity_client/lib/src/auth/dtos/signed_challenge.c.freezed.dart @@ -0,0 +1,169 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'signed_challenge.c.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +SignedChallenge _$SignedChallengeFromJson(Map json) { + return _SignedChallenge.fromJson(json); +} + +/// @nodoc +mixin _$SignedChallenge { + CredentialRequestData get firstFactorCredential => + throw _privateConstructorUsedError; + + /// Serializes this SignedChallenge to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of SignedChallenge + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $SignedChallengeCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $SignedChallengeCopyWith<$Res> { + factory $SignedChallengeCopyWith( + SignedChallenge value, $Res Function(SignedChallenge) then) = + _$SignedChallengeCopyWithImpl<$Res, SignedChallenge>; + @useResult + $Res call({CredentialRequestData firstFactorCredential}); +} + +/// @nodoc +class _$SignedChallengeCopyWithImpl<$Res, $Val extends SignedChallenge> + implements $SignedChallengeCopyWith<$Res> { + _$SignedChallengeCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of SignedChallenge + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? firstFactorCredential = null, + }) { + return _then(_value.copyWith( + firstFactorCredential: null == firstFactorCredential + ? _value.firstFactorCredential + : firstFactorCredential // ignore: cast_nullable_to_non_nullable + as CredentialRequestData, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$SignedChallengeImplCopyWith<$Res> + implements $SignedChallengeCopyWith<$Res> { + factory _$$SignedChallengeImplCopyWith(_$SignedChallengeImpl value, + $Res Function(_$SignedChallengeImpl) then) = + __$$SignedChallengeImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({CredentialRequestData firstFactorCredential}); +} + +/// @nodoc +class __$$SignedChallengeImplCopyWithImpl<$Res> + extends _$SignedChallengeCopyWithImpl<$Res, _$SignedChallengeImpl> + implements _$$SignedChallengeImplCopyWith<$Res> { + __$$SignedChallengeImplCopyWithImpl( + _$SignedChallengeImpl _value, $Res Function(_$SignedChallengeImpl) _then) + : super(_value, _then); + + /// Create a copy of SignedChallenge + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? firstFactorCredential = null, + }) { + return _then(_$SignedChallengeImpl( + firstFactorCredential: null == firstFactorCredential + ? _value.firstFactorCredential + : firstFactorCredential // ignore: cast_nullable_to_non_nullable + as CredentialRequestData, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$SignedChallengeImpl implements _SignedChallenge { + const _$SignedChallengeImpl({required this.firstFactorCredential}); + + factory _$SignedChallengeImpl.fromJson(Map json) => + _$$SignedChallengeImplFromJson(json); + + @override + final CredentialRequestData firstFactorCredential; + + @override + String toString() { + return 'SignedChallenge(firstFactorCredential: $firstFactorCredential)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$SignedChallengeImpl && + (identical(other.firstFactorCredential, firstFactorCredential) || + other.firstFactorCredential == firstFactorCredential)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, firstFactorCredential); + + /// Create a copy of SignedChallenge + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$SignedChallengeImplCopyWith<_$SignedChallengeImpl> get copyWith => + __$$SignedChallengeImplCopyWithImpl<_$SignedChallengeImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$SignedChallengeImplToJson( + this, + ); + } +} + +abstract class _SignedChallenge implements SignedChallenge { + const factory _SignedChallenge( + {required final CredentialRequestData firstFactorCredential}) = + _$SignedChallengeImpl; + + factory _SignedChallenge.fromJson(Map json) = + _$SignedChallengeImpl.fromJson; + + @override + CredentialRequestData get firstFactorCredential; + + /// Create a copy of SignedChallenge + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$SignedChallengeImplCopyWith<_$SignedChallengeImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/ion_identity_client/lib/src/auth/dtos/signed_challenge.c.g.dart b/packages/ion_identity_client/lib/src/auth/dtos/signed_challenge.c.g.dart index f0dc2d4bf8..966ba926e9 100644 --- a/packages/ion_identity_client/lib/src/auth/dtos/signed_challenge.c.g.dart +++ b/packages/ion_identity_client/lib/src/auth/dtos/signed_challenge.c.g.dart @@ -6,19 +6,15 @@ part of 'signed_challenge.c.dart'; // JsonSerializableGenerator // ************************************************************************** -SignedChallenge _$SignedChallengeFromJson(Map json) => - SignedChallenge( +_$SignedChallengeImpl _$$SignedChallengeImplFromJson( + Map json) => + _$SignedChallengeImpl( firstFactorCredential: CredentialRequestData.fromJson( json['firstFactorCredential'] as Map), - wallets: (json['wallets'] as List?) - ?.map((e) => - RegisterCompleteWallet.fromJson(e as Map)) - .toList() ?? - RequestDefaults.registerCompleteWallets, ); -Map _$SignedChallengeToJson(SignedChallenge instance) => +Map _$$SignedChallengeImplToJson( + _$SignedChallengeImpl instance) => { 'firstFactorCredential': instance.firstFactorCredential.toJson(), - 'wallets': instance.wallets.map((e) => e.toJson()).toList(), }; diff --git a/packages/ion_identity_client/lib/src/core/types/request_defaults.dart b/packages/ion_identity_client/lib/src/core/types/request_defaults.dart deleted file mode 100644 index 687d69f884..0000000000 --- a/packages/ion_identity_client/lib/src/core/types/request_defaults.dart +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: ice License 1.0 - -import 'package:ion_identity_client/src/auth/dtos/register_complete_wallet.c.dart'; - -class RequestDefaults { - // TODO: replace with ION later - static const registerCompleteWalletNetwork = 'Ton'; - static const registerCompleteWalletName = 'main'; - static const registerCompleteWallets = [ - RegisterCompleteWallet( - network: registerCompleteWalletNetwork, - name: registerCompleteWalletName, - ), - ]; -} diff --git a/packages/ion_identity_client/lib/src/wallets/services/broadcast_transaction/domain/transaction_creator/ton_transaction_creator.dart b/packages/ion_identity_client/lib/src/wallets/services/broadcast_transaction/domain/transaction_creator/ton_transaction_creator.dart index 40a0b4fb1f..00ae9c83f0 100644 --- a/packages/ion_identity_client/lib/src/wallets/services/broadcast_transaction/domain/transaction_creator/ton_transaction_creator.dart +++ b/packages/ion_identity_client/lib/src/wallets/services/broadcast_transaction/domain/transaction_creator/ton_transaction_creator.dart @@ -8,7 +8,9 @@ import 'package:ion_identity_client/src/wallets/services/broadcast_transaction/m import 'package:tonutils/tonutils.dart'; class TonTransactionCreator implements TransactionCreator { - TonTransactionCreator() : _client = TonJsonRpc(); + TonTransactionCreator({ + required String endpoint, + }) : _client = TonJsonRpc(endpoint); final TonJsonRpc _client; diff --git a/packages/ion_identity_client/lib/src/wallets/services/broadcast_transaction/domain/transaction_creator/transaction_creator_factory.dart b/packages/ion_identity_client/lib/src/wallets/services/broadcast_transaction/domain/transaction_creator/transaction_creator_factory.dart index 61bef0bd77..dfe0a386fd 100644 --- a/packages/ion_identity_client/lib/src/wallets/services/broadcast_transaction/domain/transaction_creator/transaction_creator_factory.dart +++ b/packages/ion_identity_client/lib/src/wallets/services/broadcast_transaction/domain/transaction_creator/transaction_creator_factory.dart @@ -8,12 +8,10 @@ import 'package:ion_identity_client/src/wallets/services/broadcast_transaction/d class TransactionCreatorFactory { TransactionCreatorFactory() : btcCreator = BtcTransactionCreator(), - ethCreator = EvmTransactionCreator(), - tonCreator = TonTransactionCreator(); + ethCreator = EvmTransactionCreator(); final BtcTransactionCreator btcCreator; final EvmTransactionCreator ethCreator; - final TonTransactionCreator tonCreator; TransactionCreator getCreator(String network) { switch (network.toLowerCase()) { @@ -24,9 +22,13 @@ class TransactionCreatorFactory { case 'ethereumsepolia': return ethCreator; case 'ton': + return TonTransactionCreator(endpoint: 'https://toncenter.com/api/v2/jsonRPC'); case 'tontestnet': + return TonTransactionCreator(endpoint: 'https://testnet.toncenter.com/api/v2/jsonRPC'); case 'ion': - return tonCreator; + return TonTransactionCreator(endpoint: 'https://api.mainnet.ice.io/http/v2/jsonRPC'); + case 'iontestnet': + return TonTransactionCreator(endpoint: 'https://api.testnet.ice.io/http/v2/jsonRPC'); default: // Clearly handle unknown networks throw UnsupportedError('Unsupported network: $network');