Skip to content
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

remove dao #2058

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions lib/common/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import 'package:autonomy_flutter/service/account_service.dart';
import 'package:autonomy_flutter/service/address_service.dart';
import 'package:autonomy_flutter/service/announcement/announcement_service.dart';
import 'package:autonomy_flutter/service/announcement/announcement_store.dart';
import 'package:autonomy_flutter/service/audit_service.dart';
import 'package:autonomy_flutter/service/auth_service.dart';
import 'package:autonomy_flutter/service/backup_service.dart';
import 'package:autonomy_flutter/service/canvas_client_service_v2.dart';
Expand Down Expand Up @@ -181,7 +180,6 @@ Future<void> setup() async {

injector.registerLazySingleton<NetworkService>(() => NetworkService());
// Services
final auditService = AuditServiceImpl(cloudDB);

injector.registerSingleton<ConfigurationService>(
ConfigurationServiceImpl(sharedPreferences));
Expand All @@ -195,7 +193,6 @@ Future<void> setup() async {
cloudDB,
injector(),
injector(),
auditService,
injector(),
injector(),
injector(),
Expand Down Expand Up @@ -289,8 +286,6 @@ Future<void> setup() async {
baseUrl: Environment.customerSupportURL),
));

injector.registerLazySingleton<AuditService>(() => auditService);

injector.registerLazySingleton<MerchandiseService>(
() => MerchandiseServiceImpl(MerchandiseApi(
authenticatedDio,
Expand Down
68 changes: 8 additions & 60 deletions lib/database/cloud_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,33 @@
import 'dart:async';

import 'package:autonomy_flutter/database/dao/address_dao.dart';
import 'package:autonomy_flutter/database/dao/audit_dao.dart';
import 'package:autonomy_flutter/database/dao/connection_dao.dart';
import 'package:autonomy_flutter/database/dao/persona_dao.dart';
import 'package:autonomy_flutter/database/entity/audit.dart';
import 'package:autonomy_flutter/database/entity/connection.dart';
import 'package:autonomy_flutter/database/entity/persona.dart';
import 'package:autonomy_flutter/database/entity/identity.dart';
import 'package:autonomy_flutter/database/entity/wallet_address.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/log.dart';
import 'package:autonomy_flutter/util/wallet_storage_ext.dart';
import 'package:floor/floor.dart';
import 'package:sqflite/sqflite.dart' as sqflite;

part 'cloud_database.g.dart'; // the generated code will be there
//ignore_for_file: lines_longer_than_80_chars

@TypeConverters([DateTimeConverter])
@Database(version: 9, entities: [Persona, Connection, Audit, WalletAddress])
@Database(version: 10, entities: [Connection, WalletAddress])
abstract class CloudDatabase extends FloorDatabase {
PersonaDao get personaDao;

ConnectionDao get connectionDao;

AuditDao get auditDao;

WalletAddressDao get addressDao;

Future<dynamic> removeAll() async {
await personaDao.removeAll();
await connectionDao.removeAll();
await auditDao.removeAll();
await addressDao.removeAll();
}

Future<void> copyDataFrom(CloudDatabase source) async {
await source.personaDao.getPersonas().then((personas) async {
await personaDao.insertPersonas(personas);
});
await source.connectionDao.getConnections().then((connections) async {
await connectionDao.insertConnections(connections);
});
await source.auditDao.getAudits().then((audits) async {
await auditDao.insertAudits(audits);
});
await source.addressDao.getAllAddresses().then((addresses) async {
await addressDao.insertAddresses(addresses);
});
Expand Down Expand Up @@ -143,47 +126,7 @@ final migrateCloudV4ToV5 = Migration(4, 5, (database) async {
final migrateCloudV5ToV6 = Migration(5, 6, (database) async {
await database.execute(
'CREATE TABLE IF NOT EXISTS `WalletAddress` (`address` TEXT NOT NULL, `uuid` TEXT NOT NULL, `index` INTEGER NOT NULL, `cryptoType` TEXT NOT NULL, `createdAt` INTEGER NOT NULL, `isHidden` INTEGER NOT NULL, PRIMARY KEY (`address`))');
log.info('Migrating Cloud database: created WalletAddress table');
final personaTable = await database.query('Persona');
final personas = personaTable.map((e) => Persona.fromJson(e)).toList();
log.info('Migrating Cloud database: personas '
'${personas.map((e) => e.toJson()).toList()}');
for (var persona in personas) {
List<String>? tezIndexesStr = (persona.tezosIndexes ?? '').split(',')
..removeWhere((element) => element.isEmpty);
log.info('Migrating Cloud database: tezIndexesStr $tezIndexesStr');
final tezIndexes = tezIndexesStr.map((e) => int.parse(e)).toList();
for (var index in tezIndexes) {
await database.insert(
'WalletAddress',
{
'address': await persona.wallet().getTezosAddress(index: index),
'uuid': persona.uuid,
'index': index,
'cryptoType': CryptoType.XTZ.source,
'createdAt': persona.createdAt.millisecondsSinceEpoch,
'isHidden': 0,
},
conflictAlgorithm: sqflite.ConflictAlgorithm.ignore);
}
List<String>? ethIndexesStr = (persona.ethereumIndexes ?? '').split(',')
..removeWhere((element) => element.isEmpty);
log.info('Migrating Cloud database: ethIndexesStr $ethIndexesStr');
final ethIndexes = ethIndexesStr.map((e) => int.parse(e)).toList();
for (var index in ethIndexes) {
await database.insert(
'WalletAddress',
{
'address': await persona.wallet().getETHEip55Address(index: index),
'uuid': persona.uuid,
'index': index,
'cryptoType': CryptoType.ETH.source,
'createdAt': persona.createdAt.millisecondsSinceEpoch,
'isHidden': 0,
},
conflictAlgorithm: sqflite.ConflictAlgorithm.ignore);
}
}

log.info('Migrated Cloud database from version 5 to 6');
});

Expand Down Expand Up @@ -234,6 +177,10 @@ final migrateCloudV8ToV9 = Migration(8, 9, (database) async {
log.info('Migrated Cloud database from version 8 to 9');
});

final migrateCloudV9ToV10 = Migration(9, 10, (database) async {
await database.execute('DROP TABLE IF EXISTS Audit;');
});

final cloudDatabaseMigrations = [
migrateCloudV1ToV2,
migrateCloudV2ToV3,
Expand All @@ -243,4 +190,5 @@ final cloudDatabaseMigrations = [
migrateCloudV6ToV7,
migrateCloudV7ToV8,
migrateCloudV8ToV9,
migrateCloudV9ToV10,
];
Loading
Loading