Skip to content

Commit

Permalink
feat: add registering currency after transport update (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-A4 authored Jul 19, 2023
1 parent e0ec17b commit 6c6b819
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/src/models/transport_strategy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ abstract class TransportStrategy {
/// Method depends on transport because this same [walletType] may has
/// different names in different networks.
String defaultAccountName(WalletType walletType);

/// Number of numbers after decimal point for native token.
/// For ever and venom it's 9.
int get defaultNativeCurrencyDecimal;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ mixin TransportRepositoryImpl implements TransportRepository {
Future<void> updateTransport(TransportStrategy transport) async {
final prev = _transportSubject.valueOrNull;
_transportSubject.add(transport);

final decimals = transport.defaultNativeCurrencyDecimal;
final patternDigits = decimals > 0 ? '0.${'#' * decimals}' : '0';
Currencies().register(
Currency.create(
transport.nativeTokenTicker,
decimals,
pattern: '$patternDigits S',
),
);

prev?.transport.dispose();
}

Expand Down

0 comments on commit 6c6b819

Please sign in to comment.