-
Notifications
You must be signed in to change notification settings - Fork 4
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
refactor: Performance improvements #627
base: dev
Are you sure you want to change the base?
Changes from all commits
181d0f3
c54dcb2
6795cb8
ee4e0ae
aa5b88e
94a5cd2
05419f0
dea68fd
b2a75b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,31 +148,25 @@ class AssetsService { | |
/// This stream listens for contracts from storage and load contracts if | ||
/// needed or return it from storage. | ||
Stream<List<TokenContractAsset>> contractsForAccount(Address address) { | ||
return nekotonRepository.currentTransportStream.flatMap((transport) { | ||
return Rx.combineLatest2<List<TokenContractAsset>, KeyAccount?, | ||
KeyAccount?>( | ||
return nekotonRepository.currentTransportStream.switchMap((transport) { | ||
return Rx.combineLatest2( | ||
contractsStream, | ||
nekotonRepository.seedListStream | ||
.map((list) => list.findAccountByAddress(address)), | ||
nekotonRepository.seedListStream.map( | ||
(list) => list.findAccountByAddress(address), | ||
), | ||
// we ignore result of contracts, this needed just to trigger updating | ||
(a, c) => c, | ||
).asyncExpand((account) { | ||
final wallets = | ||
account?.additionalAssets[transport.transport.group]?.tokenWallets; | ||
final group = transport.transport.group; | ||
final wallets = account?.additionalAssets[group]?.tokenWallets; | ||
if (wallets == null) return Stream.value([]); | ||
|
||
return Stream.fromFuture( | ||
Future.value( | ||
() async { | ||
return (await Future.wait( | ||
wallets.map( | ||
(e) => getTokenContractAsset(e.rootTokenContract, transport), | ||
), | ||
)) | ||
.whereNotNull() | ||
.toList(); | ||
}(), | ||
), | ||
Future.wait( | ||
wallets.map( | ||
(e) => getTokenContractAsset(e.rootTokenContract, transport), | ||
), | ||
).then((e) => e.whereNotNull().toList()), | ||
); | ||
}); | ||
}); | ||
|
@@ -213,7 +207,7 @@ class AssetsService { | |
isCustom: true, | ||
); | ||
|
||
await storage.addCustomTokenContractAsset(asset); | ||
storage.addCustomTokenContractAsset(asset); | ||
|
||
return asset; | ||
} catch (e, st) { | ||
|
@@ -263,30 +257,30 @@ class AssetsService { | |
|
||
final manifest = TonAssetsManifest.fromJson(decoded); | ||
|
||
await storage.updateSystemTokenContractAssets(manifest.tokens); | ||
storage.updateSystemTokenContractAssets(manifest.tokens); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. И тут. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. И тут |
||
} catch (e, st) { | ||
_logger.severe('_updateSystemContracts', e, st); | ||
} | ||
} | ||
|
||
/// Listen for changing contracts and remove old tokens and remove duplicated | ||
/// tokens that could be moved from custom to system. | ||
Future<void> _contractsUpdateListener( | ||
void _contractsUpdateListener( | ||
List<TokenContractAsset> systemAssets, | ||
List<TokenContractAsset> customAssets, | ||
) async { | ||
) { | ||
final duplicatedAssets = customAssets | ||
.where((e) => systemAssets.any((el) => e.address == el.address)); | ||
|
||
for (final asset in duplicatedAssets) { | ||
await storage.removeCustomTokenContractAsset(asset); | ||
storage.removeCustomTokenContractAsset(asset); | ||
} | ||
|
||
final oldAssets = | ||
customAssets.where((e) => e.version == TokenWalletVersion.oldTip3v4); | ||
|
||
for (final asset in oldAssets) { | ||
await storage.removeCustomTokenContractAsset(asset); | ||
storage.removeCustomTokenContractAsset(asset); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,10 @@ class BiometryPasswordNotStoredException implements Exception {} | |
/// Service that helps reading/updating biometry settings. | ||
@singleton | ||
class BiometryService { | ||
BiometryService(this.storage, this.appLifecycleService); | ||
BiometryService(this.storage, this.secureStorage, this.appLifecycleService); | ||
|
||
final GeneralStorageService storage; | ||
final SecureStorageService secureStorage; | ||
final AppLifecycleService appLifecycleService; | ||
|
||
final _localAuth = LocalAuthentication(); | ||
|
@@ -66,7 +67,9 @@ class BiometryService { | |
.listen((e) => storage.setIsBiometryEnabled(isEnabled: e)); | ||
|
||
// clear all passwords if biometry was disabled | ||
enabledStream.where((e) => !e).listen((e) => storage.clearKeyPasswords()); | ||
enabledStream | ||
.where((e) => !e) | ||
.listen((e) => secureStorage.clearKeyPasswords()); | ||
} | ||
|
||
/// On iOS checks face id permission and opens system setting if permission | ||
|
@@ -109,7 +112,7 @@ class BiometryService { | |
// if user want enable biometry - ask auth. | ||
try { | ||
if (!isEnabled || isEnabled && await _authenticate(localizedReason)) { | ||
await storage.setIsBiometryEnabled(isEnabled: isEnabled); | ||
storage.setIsBiometryEnabled(isEnabled: isEnabled); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. И тут тоже |
||
} | ||
} catch (_) {} | ||
} | ||
|
@@ -123,7 +126,7 @@ class BiometryService { | |
required String password, | ||
}) async { | ||
if (available) { | ||
return storage.setKeyPassword( | ||
return secureStorage.setKeyPassword( | ||
publicKey: publicKey, | ||
password: password, | ||
); | ||
|
@@ -137,7 +140,7 @@ class BiometryService { | |
required String localizedReason, | ||
required PublicKey publicKey, | ||
}) async { | ||
final password = await storage.getKeyPassword(publicKey); | ||
final password = await secureStorage.getKeyPassword(publicKey); | ||
|
||
if (password != null) { | ||
if (await _authenticate(localizedReason)) { | ||
|
@@ -153,7 +156,7 @@ class BiometryService { | |
/// Check if password of [publicKey] was stored before. | ||
Future<bool> hasKeyPassword(PublicKey publicKey) async { | ||
try { | ||
final password = await storage.getKeyPassword(publicKey); | ||
final password = await secureStorage.getKeyPassword(publicKey); | ||
return password != null; | ||
} catch (_) { | ||
return false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Без await ошибка пройдет мимо catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Функция синхронная