Skip to content

Commit

Permalink
delete persona
Browse files Browse the repository at this point in the history
Signed-off-by: phuoc <[email protected]>
  • Loading branch information
phuocbitmark committed Sep 9, 2024
1 parent 3fc485d commit a398bd3
Show file tree
Hide file tree
Showing 32 changed files with 440 additions and 1,205 deletions.
55 changes: 3 additions & 52 deletions lib/database/cloud_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,29 @@ import 'dart:async';

import 'package:autonomy_flutter/database/dao/address_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/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, WalletAddress])
@Database(version: 10, entities: [Connection, WalletAddress])
abstract class CloudDatabase extends FloorDatabase {
PersonaDao get personaDao;

ConnectionDao get connectionDao;

WalletAddressDao get addressDao;

Future<dynamic> removeAll() async {
await personaDao.removeAll();
await connectionDao.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);
});
Expand Down Expand Up @@ -135,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
145 changes: 0 additions & 145 deletions lib/database/cloud_database.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 0 additions & 39 deletions lib/database/dao/persona_dao.dart

This file was deleted.

Loading

0 comments on commit a398bd3

Please sign in to comment.