-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: rework subscription logic, now TonWalletState & Toke…
…nWalletState available (#92)
- Loading branch information
Showing
10 changed files
with
945 additions
and
443 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export 'token_wallet_ordinary_transaction.dart'; | ||
export 'token_wallet_state.dart'; | ||
export 'token_wallet_subscription.dart'; |
62 changes: 62 additions & 0 deletions
62
lib/src/models/token_wallet_related/token_wallet_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:nekoton_repository/nekoton_repository.dart'; | ||
|
||
/// State of [TokenWallet] that allows tracking when subscription was created | ||
/// successfully or when it failed with some error. | ||
/// | ||
/// To detect which state is active, use [hasWallet] and [hasError]. | ||
@immutable | ||
class TokenWalletState extends Equatable { | ||
/// Create state with error. | ||
const TokenWalletState.error({ | ||
required Object err, | ||
required this.owner, | ||
required this.rootTokenContract, | ||
}) : wallet = null, | ||
error = err; | ||
|
||
/// Create state with wallet | ||
TokenWalletState.wallet(TokenWallet w) | ||
: error = null, | ||
owner = w.owner, | ||
rootTokenContract = w.rootTokenContract, | ||
wallet = w; | ||
|
||
/// Allows to track for which wallet this state was created. | ||
/// This can be useful when [wallet] is null and we cannot detect it. | ||
final Address owner; | ||
final Address rootTokenContract; | ||
|
||
/// Wallet that could be created. | ||
/// If wallet was created, then [hasWallet] returns true and you can use it | ||
/// as usual. | ||
final TokenWallet? wallet; | ||
|
||
/// Any error that could be thrown during creating subscription. | ||
/// Typically, this is [FfiException] or | ||
/// [TokenWalletRetrySubscriptionMissedAsset], but may be any other type. | ||
final Object? error; | ||
|
||
bool get hasWallet => wallet != null; | ||
|
||
bool get hasError => error != null; | ||
|
||
@override | ||
List<Object?> get props => [owner, rootTokenContract, error, wallet]; | ||
} | ||
|
||
/// Exception that will be thrown from any methods when user outside package | ||
/// called method without making sure that state was initialized. | ||
class TokenWalletStateNotInitializedException implements Exception { | ||
@override | ||
String toString() => ''' | ||
`TokenWalletState.wallet` was not initialized. | ||
Try calling `TokenWalletRepository.retrySubscriptions` | ||
'''; | ||
} | ||
|
||
/// Exception that will be thrown from | ||
/// [TokenWalletRepository.retryTokenSubscription] when asset with specified | ||
/// owner and rootTokenContract won't be found. | ||
class TokenWalletRetrySubscriptionMissedAsset implements Exception {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:nekoton_repository/nekoton_repository.dart'; | ||
|
||
/// State of [TonWallet] that allows tracking when subscription was created | ||
/// successfully or when it failed with some error. | ||
/// | ||
/// To detect which state is active, use [hasWallet] and [hasError]. | ||
@immutable | ||
class TonWalletState extends Equatable { | ||
/// Create state with error. | ||
const TonWalletState.error({ | ||
required Object err, | ||
required this.address, | ||
}) : wallet = null, | ||
error = err; | ||
|
||
/// Create state with wallet | ||
TonWalletState.wallet(TonWallet w) | ||
: error = null, | ||
address = w.address, | ||
wallet = w; | ||
|
||
/// Allows to track for which wallet this state was created. | ||
/// This can be useful when [wallet] is null and we cannot detect it. | ||
final Address address; | ||
|
||
/// Wallet that could be created. | ||
/// If wallet was created, then [hasWallet] returns true and you can use it | ||
/// as usual. | ||
final TonWallet? wallet; | ||
|
||
/// Any error that could be thrown during creating subscription. | ||
/// Typically, this is [FfiException] or | ||
/// [TonWalletRetrySubscriptionMissedAsset] but may be any other type. | ||
final Object? error; | ||
|
||
bool get hasWallet => wallet != null; | ||
|
||
bool get hasError => error != null; | ||
|
||
@override | ||
List<Object?> get props => [address, error, wallet]; | ||
} | ||
|
||
/// Exception that will be thrown from any methods when user outside package | ||
/// called method without making sure that state was initialized. | ||
class TonWalletStateNotInitializedException implements Exception { | ||
@override | ||
String toString() => ''' | ||
`TonWalletState.wallet` was not initialized. | ||
Try calling `TonWalletRepository.retrySubscriptions` | ||
'''; | ||
} | ||
|
||
/// Exception that will be thrown from [TonWalletRepository.retrySubscriptions] | ||
/// when asset with specified address won't be found | ||
class TonWalletRetrySubscriptionMissedAsset implements Exception {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.