-
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.
* feat: ton (wip) * fix: rebase * fix: update nekoton_bridge (`estimateMinAttachedAmount`) --------- Co-authored-by: Egor Komarov <[email protected]>
- Loading branch information
Showing
11 changed files
with
318 additions
and
62 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
lib/src/models/token_wallet_related/generic_token_wallet.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,30 @@ | ||
import 'package:flutter_nekoton_bridge/flutter_nekoton_bridge.dart'; | ||
|
||
part 'jetton_token_wallet.dart'; | ||
part 'tip3_token_wallet.dart'; | ||
|
||
sealed class GenericTokenWallet { | ||
RefreshingInterface get inner; | ||
Transport get transport; | ||
BigInt get balance; | ||
Money get moneyBalance; | ||
Currency get currency; | ||
Address get rootTokenContract; | ||
Address get tokenAddress; | ||
Address get owner; | ||
Symbol get symbol; | ||
ContractState get contractState; | ||
Stream<void> get fieldUpdatesStream; | ||
Stream<BigInt> get onBalanceChangedStream; | ||
Stream<Money> get onMoneyBalanceChangedStream; | ||
Stream< | ||
( | ||
List<TransactionWithData<TokenWalletTransaction?>>, | ||
TransactionsBatchInfo | ||
)> get onTransactionsFoundStream; | ||
Future<ContractState> getContractState(); | ||
Future<void> preloadTransactions(String? fromLt); | ||
void onBalanceChanged(String balance); | ||
void onTransactionsFound(String payload); | ||
void dispose(); | ||
} |
104 changes: 104 additions & 0 deletions
104
lib/src/models/token_wallet_related/jetton_token_wallet.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,104 @@ | ||
part of 'generic_token_wallet.dart'; | ||
|
||
class JettonTokenWallet extends GenericTokenWallet { | ||
JettonTokenWallet(this._wallet, this._symbol) | ||
: _currency = _getCurrency(_symbol); | ||
|
||
static Future<JettonTokenWallet> subscribe({ | ||
required Transport transport, | ||
required Address owner, | ||
required Address rootTokenContract, | ||
required Symbol symbol, | ||
}) async => | ||
JettonTokenWallet( | ||
await JettonWallet.subscribe( | ||
transport: transport, | ||
owner: owner, | ||
rootTokenContract: rootTokenContract, | ||
), | ||
symbol, | ||
); | ||
|
||
final JettonWallet _wallet; | ||
final Symbol _symbol; | ||
final Currency _currency; | ||
|
||
@override | ||
Currency get currency => _currency; | ||
|
||
@override | ||
JettonWallet get inner => _wallet; | ||
|
||
@override | ||
Transport get transport => _wallet.transport; | ||
|
||
@override | ||
BigInt get balance => _wallet.balance; | ||
|
||
@override | ||
Money get moneyBalance => Money.fromBigIntWithCurrency(balance, currency); | ||
|
||
@override | ||
Address get rootTokenContract => _wallet.rootTokenContract; | ||
|
||
@override | ||
Address get tokenAddress => _wallet.tokenAddress; | ||
|
||
@override | ||
Address get owner => _wallet.owner; | ||
|
||
@override | ||
Symbol get symbol => _symbol; | ||
|
||
@override | ||
ContractState get contractState => _wallet.contractState; | ||
|
||
@override | ||
Stream<void> get fieldUpdatesStream => _wallet.fieldUpdatesStream; | ||
|
||
@override | ||
Stream<BigInt> get onBalanceChangedStream => _wallet.onBalanceChangedStream; | ||
|
||
@override | ||
Stream<Money> get onMoneyBalanceChangedStream => onBalanceChangedStream.map( | ||
(balance) => Money.fromBigIntWithCurrency(balance, currency), | ||
); | ||
|
||
@override | ||
Stream< | ||
( | ||
List<TransactionWithData<TokenWalletTransaction?>>, | ||
TransactionsBatchInfo | ||
)> get onTransactionsFoundStream => _wallet.onTransactionsFoundStream; | ||
|
||
@override | ||
Future<ContractState> getContractState() => _wallet.getContractState(); | ||
|
||
@override | ||
Future<void> preloadTransactions([String? fromLt]) => | ||
_wallet.preloadTransactions(fromLt); | ||
|
||
@override | ||
void onBalanceChanged(String balance) => _wallet.onBalanceChanged(balance); | ||
|
||
@override | ||
void onTransactionsFound(String payload) => | ||
_wallet.onTransactionsFound(payload); | ||
|
||
@override | ||
void dispose() => _wallet.dispose(); | ||
} | ||
|
||
Currency _getCurrency(Symbol symbol) { | ||
final patternDigits = | ||
symbol.decimals > 0 ? '0.${'#' * symbol.decimals}' : '0'; | ||
final currency = Currency.create( | ||
symbol.name, | ||
symbol.decimals, | ||
symbol: symbol.name, | ||
pattern: patternDigits, | ||
); | ||
Currencies().register(currency); | ||
|
||
return currency; | ||
} |
84 changes: 84 additions & 0 deletions
84
lib/src/models/token_wallet_related/tip3_token_wallet.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,84 @@ | ||
part of 'generic_token_wallet.dart'; | ||
|
||
class Tip3TokenWallet extends GenericTokenWallet { | ||
Tip3TokenWallet(this._wallet); | ||
|
||
static Future<Tip3TokenWallet> subscribe({ | ||
required Transport transport, | ||
required Address owner, | ||
required Address rootTokenContract, | ||
}) async => | ||
Tip3TokenWallet( | ||
await TokenWallet.subscribe( | ||
transport: transport, | ||
owner: owner, | ||
rootTokenContract: rootTokenContract, | ||
), | ||
); | ||
|
||
final TokenWallet _wallet; | ||
|
||
@override | ||
TokenWallet get inner => _wallet; | ||
|
||
@override | ||
Transport get transport => _wallet.transport; | ||
|
||
@override | ||
BigInt get balance => _wallet.balance; | ||
|
||
@override | ||
Money get moneyBalance => _wallet.moneyBalance; | ||
|
||
@override | ||
Currency get currency => _wallet.currency; | ||
|
||
@override | ||
Address get rootTokenContract => _wallet.rootTokenContract; | ||
|
||
@override | ||
Address get tokenAddress => _wallet.tokenAddress; | ||
|
||
@override | ||
Address get owner => _wallet.owner; | ||
|
||
@override | ||
Symbol get symbol => _wallet.symbol; | ||
|
||
@override | ||
ContractState get contractState => _wallet.contractState; | ||
|
||
@override | ||
Stream<void> get fieldUpdatesStream => _wallet.fieldUpdatesStream; | ||
|
||
@override | ||
Stream<BigInt> get onBalanceChangedStream => _wallet.onBalanceChangedStream; | ||
|
||
@override | ||
Stream<Money> get onMoneyBalanceChangedStream => | ||
_wallet.onMoneyBalanceChangedStream; | ||
|
||
@override | ||
Stream< | ||
( | ||
List<TransactionWithData<TokenWalletTransaction?>>, | ||
TransactionsBatchInfo | ||
)> get onTransactionsFoundStream => _wallet.onTransactionsFoundStream; | ||
|
||
@override | ||
Future<ContractState> getContractState() => _wallet.getContractState(); | ||
|
||
@override | ||
Future<void> preloadTransactions([String? fromLt]) => | ||
_wallet.preloadTransactions(fromLt); | ||
|
||
@override | ||
void onBalanceChanged(String balance) => _wallet.onBalanceChanged(balance); | ||
|
||
@override | ||
void onTransactionsFound(String payload) => | ||
_wallet.onTransactionsFound(payload); | ||
|
||
@override | ||
void dispose() => _wallet.dispose(); | ||
} |
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,3 +1,4 @@ | ||
export 'generic_token_wallet.dart'; | ||
export 'token_wallet_ordinary_transaction.dart'; | ||
export 'token_wallet_state.dart'; | ||
export 'token_wallet_subscription.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
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.