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

feat: store token list localdb #1498

Merged
merged 113 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
01f8db9
wip: profile qrcode new padding, avatar circle bg color and close but…
Jaxiii Jun 4, 2024
7e37189
fix: qr code spacing
Jaxiii Jun 4, 2024
357deb0
fix: styling
Jaxiii Jun 4, 2024
21284c7
Merge branch 'master' into fix/profile-spacing-colors
Jaxiii Jun 5, 2024
6c6c523
fix: change CupertinoSwitch colors
Jaxiii Jun 5, 2024
663b907
wip: dto, dao, respo and service
Jaxiii Jun 5, 2024
717569e
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Jun 5, 2024
99c95ee
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Jun 10, 2024
901adaa
fix: list tests
Jaxiii Jun 10, 2024
4e25645
fix: styling
Jaxiii Jun 10, 2024
b34fc1b
wip: removing proxies
Jaxiii Jun 11, 2024
622c54b
wip: removing dao
Jaxiii Jun 11, 2024
3e600e5
wip: styling
Jaxiii Jun 11, 2024
bc69045
wip: styling
Jaxiii Jun 11, 2024
ad18263
wip: csv init
Jaxiii Jun 11, 2024
b335ea8
fix: styling
Jaxiii Jun 11, 2024
6936161
wip: localdb calls
Jaxiii Jun 13, 2024
63b7829
wip: move csv files to assets
Jaxiii Jun 13, 2024
797d6fc
feat: add csv as an asset
Jaxiii Jun 13, 2024
d5983d4
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Jun 13, 2024
7d7b978
wip: linter
Jaxiii Jun 13, 2024
dc52a98
wip: linter
Jaxiii Jun 13, 2024
972ca37
wip: linter
Jaxiii Jun 13, 2024
5f7b720
wip: remove dto and memory list methods
Jaxiii Jun 14, 2024
43036de
wip: remove explicitly font family styling
Jaxiii Jun 14, 2024
463c075
wip: add header - titles to csv
Jaxiii Jun 14, 2024
f686021
wip: add isolate to init token db row
Jaxiii Jun 14, 2024
9a7536e
wip: add isolate and transaction to insert token, clean up tests
Jaxiii Jun 14, 2024
12f2419
wip: populate db on list change
Jaxiii Jun 14, 2024
2c148a4
wip: change datetime to millisecs since epoch
Jaxiii Jun 15, 2024
48ba80f
timestamp on filename
Jaxiii Jun 17, 2024
ce311e3
wip: timestamped csv file and timespamp based init
Jaxiii Jun 17, 2024
cabc328
fix: linter
Jaxiii Jun 17, 2024
e15eb35
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Jun 17, 2024
0e0da4f
wip: sync getToken
Jaxiii Jun 18, 2024
38180f9
wip: remove in memory json
Jaxiii Jun 18, 2024
a78fced
wip: getToken async
Jaxiii Jun 18, 2024
8b77cf2
feat: getToken from localdb
Jaxiii Jun 24, 2024
18c61b5
fix: tests
Jaxiii Jun 24, 2024
6a498de
fix: styling
Jaxiii Jun 24, 2024
c1d7be2
fix: comments
Jaxiii Jun 24, 2024
9bb6135
fix: imports
Jaxiii Jun 24, 2024
72ccf55
fix: tests
Jaxiii Jun 24, 2024
6ea9b7f
fix: tests
Jaxiii Jun 24, 2024
9ed46a9
wip: move init and getToken to repository
Jaxiii Jun 25, 2024
4c03680
wip: move TokenListRepo outside model scope
Jaxiii Jun 25, 2024
4bb164b
wip: chuncked stream data to isolate
Jaxiii Jun 26, 2024
e5637fc
feat: token conversion rate refresh
Jaxiii Jun 28, 2024
45be1b6
fix: styling
Jaxiii Jun 28, 2024
3b50d0f
wip: remove token service
Jaxiii Jul 1, 2024
b2dab55
fix: remove future from build method
Jaxiii Jul 1, 2024
7ea3202
fix: mount on async gap
Jaxiii Jul 1, 2024
89cbcf4
fix: tests
Jaxiii Jul 1, 2024
70387fd
feat: mocked and memory test
Jaxiii Jul 1, 2024
160a1e5
wip: get token list file from ec_backend
Jaxiii Jul 3, 2024
d5683b4
fix: naming
Jaxiii Jul 3, 2024
6467472
wip: network stream token list
Jaxiii Jul 7, 2024
76f98f6
wip: remove unused dto
Jaxiii Jul 7, 2024
3ccff66
wip: remove token assets from pubspec
Jaxiii Jul 7, 2024
4da836d
wip: intl version
Jaxiii Jul 7, 2024
6b3eba4
wip: add .g client
Jaxiii Jul 8, 2024
97e471b
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Jul 8, 2024
6dd5fee
feat: md5 hash
Jaxiii Jul 9, 2024
02fd984
feat: md5 hash
Jaxiii Jul 9, 2024
7e3626a
fix: analyzer and dcm
Jaxiii Jul 9, 2024
67c4617
fix: parseTags & parseExtensions
Jaxiii Jul 10, 2024
57bf0e8
fix: remove unused endpoint ref
Jaxiii Jul 10, 2024
55e54e3
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Jul 11, 2024
ac9aa96
fix: api calls naming
Jaxiii Jul 11, 2024
a9da75c
refact: naming
Jaxiii Jul 12, 2024
f43f8fd
refact: api
Jaxiii Jul 12, 2024
de304f4
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Jul 12, 2024
52be837
Merge branch 'master' into feat/store-token-list-localdb
ookami-kb Jul 15, 2024
ac656ed
fix: clean up
Jaxiii Jul 15, 2024
269079c
fix: clean up
Jaxiii Jul 15, 2024
d88a79c
fix: clean up
Jaxiii Jul 15, 2024
01a735e
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Jul 15, 2024
fbea8ae
fix: token file stream codec error
Jaxiii Jul 16, 2024
cdda44d
refact: arg naming style
Jaxiii Jul 16, 2024
6efacdd
fix: remove future from build method
Jaxiii Jul 17, 2024
7ba20cb
fix: analyzer
Jaxiii Jul 17, 2024
9536499
minor upd
justinenerio Jul 23, 2024
841a0a1
refact: remove async cache
Jaxiii Jul 26, 2024
1b0518f
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Jul 31, 2024
50fb0f4
add schema
Jaxiii Jul 31, 2024
37e3d39
upd
ookami-kb Aug 1, 2024
9851a7b
upd
ookami-kb Aug 1, 2024
9851d12
upd
ookami-kb Aug 2, 2024
bf32d1e
remove extensions
ookami-kb Aug 2, 2024
8cdbe57
remove extensions
ookami-kb Aug 2, 2024
9a3563e
update schema
ookami-kb Aug 2, 2024
51a7f04
wip: isolate token list
Jaxiii Aug 9, 2024
f959990
wip: 2 step init token db
Jaxiii Aug 9, 2024
08454e0
fix: dcm
Jaxiii Aug 12, 2024
a6a7059
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Aug 12, 2024
052a45a
fix: null checker
Jaxiii Aug 13, 2024
3966ae1
fix: isolate scope & file hash
Jaxiii Aug 13, 2024
6e60d45
upd
Jaxiii Aug 14, 2024
dd363aa
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Aug 15, 2024
17b8408
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Aug 16, 2024
327699a
upd
Jaxiii Aug 16, 2024
a6a05df
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Aug 21, 2024
f02ec0d
upd schemas
Jaxiii Aug 23, 2024
05deaac
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Aug 28, 2024
18e1926
Merge branch 'master' into feat/store-token-list-localdb
Merculiar Sep 2, 2024
f351ecc
Merge branch 'master' into feat/store-token-list-localdb
justinenerio Sep 3, 2024
dc4c0b6
Merge branch 'master' into feat/store-token-list-localdb
justinenerio Sep 12, 2024
58716a9
Merge branch 'master' into feat/store-token-list-localdb
ookami-kb Sep 12, 2024
78da258
upd
ookami-kb Sep 12, 2024
ccc8823
upd
ookami-kb Sep 12, 2024
944af02
upd
ookami-kb Sep 12, 2024
998079f
upd
ookami-kb Sep 12, 2024
08aefe2
upd
ookami-kb Sep 12, 2024
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
2 changes: 1 addition & 1 deletion packages/espressocash_app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ splash:
dart run flutter_native_splash:create

update_tokens:
dart run tool/update_token_list.dart
dart run tool/update_tokens.dart

flutter_test:
dart run $(DART_TEST_DEFINITIONS) tool/tests_setup.dart
Expand Down
Binary file not shown.
22 changes: 20 additions & 2 deletions packages/espressocash_app/lib/data/db/db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class OutgoingTransferRows extends Table {
Set<Column<Object>> get primaryKey => {id};
}

const int latestVersion = 57;
const int latestVersion = 58;

const _tables = [
OutgoingTransferRows,
Expand All @@ -39,6 +39,7 @@ const _tables = [
TransactionRequestRows,
TokenBalanceRows,
ConversionRatesRows,
TokenRows,
];

@lazySingleton
Expand Down Expand Up @@ -128,7 +129,6 @@ class MyDatabase extends _$MyDatabase {
await m.addColumn(onRampOrderRows, onRampOrderRows.referenceNumber);
await m.addColumn(onRampOrderRows, onRampOrderRows.feeAmount);
}

if (from >= 40 && from < 54) {
await m.addColumn(offRampOrderRows, offRampOrderRows.authToken);
await m.addColumn(offRampOrderRows, offRampOrderRows.moreInfoUrl);
Expand Down Expand Up @@ -161,6 +161,9 @@ class MyDatabase extends _$MyDatabase {
if (from < 57) {
await m.addColumn(onRampOrderRows, onRampOrderRows.bridgeAmount);
}
if (from < 58) {
await m.createTable(tokenRows);
}
},
);
}
Expand Down Expand Up @@ -329,3 +332,18 @@ class ConversionRatesRows extends Table {
@override
Set<Column<Object>> get primaryKey => {token, fiatCurrency};
}

class TokenRows extends Table {
const TokenRows();

IntColumn get chainId => integer()();
TextColumn get address => text()();
TextColumn get symbol => text()();
TextColumn get name => text()();
IntColumn get decimals => integer()();
TextColumn get logoURI => text().nullable()();
BoolColumn get isStablecoin => boolean()();

@override
Set<Column> get primaryKey => {chainId, address};
}
4 changes: 0 additions & 4 deletions packages/espressocash_app/lib/di.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:solana/solana.dart';

import 'config.dart';
import 'di.config.dart';
import 'features/tokens/token_list.dart';

final sl = GetIt.instance;

Expand All @@ -28,9 +27,6 @@ abstract class AppModule {
@lazySingleton
Dio get dio => Dio();

@lazySingleton
TokenList get tokenList => TokenList();

@lazySingleton
SolanaClient get solanaClient => SolanaClient(
rpcUrl: Uri.parse(solanaRpcUrl),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import '../../../data/db/db.dart';
import '../../outgoing_direct_payments/data/repository.dart';
import '../../outgoing_dln_payments/data/repository.dart';
import '../../outgoing_link_payments/data/repository.dart';
import '../../tokens/token_list.dart';
import '../../transaction_request/models/transaction_request.dart';
import '../models/activity.dart';

Expand All @@ -14,10 +13,10 @@ extension PaymentRequestRowToActivityExt on PaymentRequestRow {
}

extension ODPRowToActivityExt on ODPRow {
Activity toActivity(TokenList tokens) => Activity.outgoingDirectPayment(
Future<Activity> toActivity() async => Activity.outgoingDirectPayment(
id: id,
created: created,
data: toModel(tokens),
data: await toModel(),
);
}

Expand All @@ -30,10 +29,10 @@ extension OutgoingDlnPaymentRowToActivityExt on OutgoingDlnPaymentRow {
}

extension OLPRowToActivityExt on OLPRow {
Activity toActivity(TokenList tokens) => Activity.outgoingLinkPayment(
Future<Activity> toActivity() async => Activity.outgoingLinkPayment(
id: id,
created: created,
data: toModel(tokens),
data: await toModel(),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@ import '../../currency/models/currency.dart';
import '../../outgoing_direct_payments/data/repository.dart';
import '../../outgoing_link_payments/data/repository.dart';
import '../../payment_request/data/repository.dart';
import '../../tokens/token_list.dart';
import '../../transaction_request/service/tr_service.dart';
import '../models/activity.dart';
import '../models/transaction.dart';
import 'activity_builder.dart';

@injectable
class TransactionRepository {
const TransactionRepository(this._db, this._tokens);
const TransactionRepository(this._db);

final MyDatabase _db;
final TokenList _tokens;

Stream<IList<String>> watchAll() {
final query = _db.select(_db.transactionRows)
Expand Down Expand Up @@ -96,13 +94,13 @@ class TransactionRepository {

final odp = _db.oDPRows.findActivityOrNull(
where: (row) => row.txId.equals(txId),
builder: (pr) => pr.toActivity(_tokens),
builder: (pr) => pr.toActivity(),
ignoreWhen: (row) => row.status != ODPStatusDto.success,
);

final olp = _db.oLPRows.findActivityOrNull(
where: (row) => row.txId.equals(txId),
builder: (pr) => pr.toActivity(_tokens),
builder: (pr) => pr.toActivity(),
ignoreWhen: (row) => const [OLPStatusDto.withdrawn, OLPStatusDto.canceled]
.contains(row.status)
.not(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import '../../outgoing_link_payments/data/repository.dart';
import '../../payment_request/data/repository.dart';
import '../../ramp/services/off_ramp_order_service.dart';
import '../../ramp/services/on_ramp_order_service.dart';
import '../../tokens/token_list.dart';
import '../../transaction_request/service/tr_service.dart';
import '../data/activity_builder.dart';
import '../models/activity.dart';
Expand All @@ -19,14 +18,12 @@ import '../models/activity.dart';
class PendingActivitiesRepository {
const PendingActivitiesRepository(
this._db,
this._tokens,
this._onRampOrderService,
this._offRampOrderService,
this._trService,
);

final MyDatabase _db;
final TokenList _tokens;
final OnRampOrderService _onRampOrderService;
final OffRampOrderService _offRampOrderService;
final TRService _trService;
Expand All @@ -49,10 +46,14 @@ class PendingActivitiesRepository {

final oprStream =
opr.watch().map((rows) => rows.map((r) => r.toActivity()));
final odpStream =
odp.watch().map((rows) => rows.map((r) => r.toActivity(_tokens)));
final olpStream =
olp.watch().map((rows) => rows.map((r) => r.toActivity(_tokens)));

final odpStream = odp
.watch()
.asyncMap((rows) async => Future.wait(rows.map((r) => r.toActivity())));

final olpStream = olp
.watch()
.asyncMap((rows) async => Future.wait(rows.map((r) => r.toActivity())));

final outgoingDlnStream = outgoingDlnPayment
.watch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,43 @@ class PaymentRequestTile extends StatefulWidget {
}

class _PaymentRequestTileState extends State<PaymentRequestTile> {
late Stream<PaymentRequest> _stream;
late Stream<(PaymentRequest, String)> _stream;

@override
void initState() {
super.initState();
_stream = watchPaymentRequest(widget.id);
_stream = watchPaymentRequest(widget.id).asyncMap((p) async {
if (!mounted) return (p, '');

return (p, await p.formattedAmount(DeviceLocale.localeOf(context)));
});
}

@override
Widget build(BuildContext context) => StreamBuilder<PaymentRequest>(
Widget build(BuildContext context) => StreamBuilder<(PaymentRequest, String)>(
stream: _stream,
builder: (context, snapshot) {
final data = snapshot.data;

return data == null
return (data == null)
? SizedBox.shrink(key: ValueKey(widget.id))
: CpActivityTile(
key: ValueKey(widget.id),
title: context.l10n.paymentRequestTitle,
icon: Assets.icons.paymentIcon.svg(),
timestamp: context.formatDate(data.created),
incomingAmount:
data.formattedAmount(DeviceLocale.localeOf(context)),
status: switch (data.state) {
timestamp: context.formatDate(data.$1.created),
incomingAmount: data.$2,
status: switch (data.$1.state) {
PaymentRequestState.initial =>
CpActivityTileStatus.inProgress,
PaymentRequestState.completed =>
CpActivityTileStatus.success,
PaymentRequestState.error => CpActivityTileStatus.failure,
},
onTap: () => PaymentRequestScreen.push(context, id: data.id),
onTap: () => PaymentRequestScreen.push(
context,
id: data.$1.id,
),
showIcon: widget.showIcon,
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class _PinInputDisplayWidgetState extends State<PinInputDisplayWidget> {
Text(
message.toUpperCase(),
style: Theme.of(context).textTheme.titleSmall?.copyWith(
fontFamily: 'Roboto App',
fontWeight: FontWeight.w700,
fontSize: 17,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:collection/collection.dart';
import 'package:dfunc/dfunc.dart';
import 'package:drift/drift.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:injectable/injectable.dart';
Expand All @@ -7,15 +8,15 @@ import '../../../data/db/db.dart';
import '../../accounts/auth_scope.dart';
import '../../currency/models/amount.dart';
import '../../currency/models/currency.dart';
import '../../tokens/data/token_repository.dart';
import '../../tokens/token.dart';
import '../../tokens/token_list.dart';

@Singleton(scope: authScope)
class TokenBalancesRepository {
const TokenBalancesRepository(this._db, this._tokens);
const TokenBalancesRepository(this._db, this._tokenRepository);

final MyDatabase _db;
final TokenList _tokens;
final TokenRepository _tokenRepository;

Future<CryptoAmount> read(Token token) async {
final query = _db.tokenBalanceRows.select()
Expand All @@ -36,10 +37,9 @@ class TokenBalancesRepository {
..where((tbl) => tbl.amount.isBiggerThanValue(0));

return query.get().then(
(rows) => rows
.map((row) => _tokens.findTokenByMint(row.token))
.whereNotNull()
.toISet(),
(rows) => Future.wait(
rows.map((row) async => _tokenRepository.getToken(row.token)),
).then((tokens) => tokens.whereNotNull().toISet()),
);
}

Expand All @@ -53,11 +53,10 @@ class TokenBalancesRepository {
tbl.token.isNotIn(ignoreTokens.map((e) => e.address).toList()),
);

return query.watch().map(
(rows) => rows
.map((row) => _tokens.findTokenByMint(row.token))
.whereNotNull()
.toISet(),
return query.watch().asyncMap(
(rows) async => Future.wait(
rows.map((row) async => _tokenRepository.getToken(row.token)),
).then((tokens) => tokens.whereNotNull().toISet()),
);
}

Expand All @@ -71,25 +70,19 @@ class TokenBalancesRepository {
tbl.token.isNotIn(ignoreTokens.map((e) => e.address).toList()),
);

return query.watch().map(
(rows) => rows
.map((row) {
final token = _tokens.findTokenByMint(row.token);

if (ignoreTokens.contains(token)) {
return null;
}

return token == null
? null
: CryptoAmount(
return query.watch().asyncMap(
(rows) async => Future.wait(
rows.map(
(row) async => _tokenRepository.getToken(row.token).letAsync(
(token) => token?.let(
(t) => CryptoAmount(
value: row.amount,
cryptoCurrency: CryptoCurrency(token: token),
);
})
.whereNotNull()
.sortedBy((element) => element.token.name)
.toIList(),
cryptoCurrency: CryptoCurrency(token: t),
),
),
),
),
).then((balances) => balances.whereNotNull().toIList()),
);
}

Expand Down
Loading
Loading