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: send token #1524

Open
wants to merge 226 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
226 commits
Select commit Hold shift + click to select a range
dd5937e
upd
justinenerio May 7, 2024
3060558
upd
justinenerio May 8, 2024
18d2b78
upd
justinenerio May 8, 2024
e700479
Merge branch 'master' into token-list
ookami-kb May 8, 2024
6bc5115
upd
ookami-kb May 8, 2024
2f6986a
upd minimum balance
justinenerio May 9, 2024
621a13e
Merge commit 'a588f4fb36b5b96cd5f3bf227525191ad67f6c94' into token-list
justinenerio May 21, 2024
d6ffcf0
upd
justinenerio May 22, 2024
c42d8aa
upd
justinenerio May 22, 2024
57cf890
upd
justinenerio May 22, 2024
1d3d0c3
upd
justinenerio May 22, 2024
b301e1e
upd
justinenerio May 22, 2024
d85c988
Merge commit '57cf890558e7bc10d20909faf7eaaf68a74e468b' into token-list
justinenerio May 22, 2024
23e1c73
upd
justinenerio May 23, 2024
56ddddd
upd repository
justinenerio May 23, 2024
6575627
Merge commit '1c6ec24cd1bfd0adf4a5452ec57fa1184ef631b9' into token-list
justinenerio May 23, 2024
0ae33db
upd
justinenerio May 28, 2024
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
7aee4fe
Merge commit 'ae41632ca00f8a38ea5e111213b65ea5c0d90681' into token-de…
justinenerio Jun 7, 2024
25055fe
upd
justinenerio Jun 7, 2024
31a9569
upd
justinenerio Jun 7, 2024
738f437
upd
justinenerio Jun 7, 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
6dfd638
Merge branch 'master' into token-details-page
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
ee36ffa
wip: paddings and placements
Jaxiii Jun 13, 2024
e6569cb
Merge branch 'master' into token-details-page
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
6d3e9fb
wip: info dialog
Jaxiii Jun 17, 2024
179d804
fix: styling
Jaxiii Jun 17, 2024
0cd8cf3
fix: linter
Jaxiii Jun 17, 2024
248ac31
Merge branch 'master' into token-details-page
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
3c26aa6
remove unused files
justinenerio Jun 18, 2024
a78fced
wip: getToken async
Jaxiii Jun 18, 2024
cc7614c
feat: token info dark background
Jaxiii Jun 19, 2024
1c7cc4c
wip: recent activity
Jaxiii Jun 20, 2024
be3c7e9
feat: token mint address
Jaxiii Jun 20, 2024
8c352bb
wip: token tx list
Jaxiii Jun 22, 2024
d133768
wip: polish
Jaxiii Jun 22, 2024
d338fc3
wip: scroll animation and amount value
Jaxiii Jun 23, 2024
173cf9b
fix: styling
Jaxiii Jun 23, 2024
7e65826
fix: stylinh
Jaxiii Jun 23, 2024
21fd4ae
fix: linter
Jaxiii Jun 23, 2024
26599fc
fix: dep cycle
Jaxiii Jun 23, 2024
5ff07a8
db pump version
Jaxiii Jun 23, 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
9350050
fix: transaction collision
Jaxiii Jun 28, 2024
ac3909f
fix: linter & styling
Jaxiii Jun 28, 2024
4444295
wip: send token layout
Jaxiii Jun 30, 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
96f039d
fix: first opening price fetch
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
e64c931
Merge branch 'master' into token-details-page
Jaxiii Jul 8, 2024
6b437ee
fix: merge imports
Jaxiii Jul 8, 2024
96d1a79
fix: details screen textspan fiat amount null checker
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
0ff6ace
Merge branch 'feat/store-token-list-localdb' into token-details-page
Jaxiii Jul 10, 2024
6c85379
feat: local token db and better tx updater
Jaxiii Jul 11, 2024
2c2b592
fix: db bump and dcm
Jaxiii Jul 11, 2024
ce507ce
fix: db_schemas
Jaxiii Jul 11, 2024
55e54e3
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Jul 11, 2024
eb7880a
wip: update call
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
003bc53
Merge branch 'feat/store-token-list-localdb' into token-details-page
Jaxiii Jul 12, 2024
95eb4b4
refact: naming
Jaxiii Jul 12, 2024
59a0fd4
Merge branch 'token-details-page' into feat/send-token
Jaxiii Jul 12, 2024
5bfaeca
fix: naming and amount decimals
Jaxiii Jul 12, 2024
29c611c
feat: i10n
Jaxiii Jul 13, 2024
acc546b
feat: i10l file
Jaxiii Jul 13, 2024
623e835
refact: convert screen to stateless
Jaxiii Jul 13, 2024
e207875
fix: dcm styling
Jaxiii Jul 14, 2024
be21a21
Merge branch 'token-details-page' into feat/send-token
Jaxiii Jul 14, 2024
ca21de5
wip: balance loader
Jaxiii Jul 14, 2024
52be837
Merge branch 'master' into feat/store-token-list-localdb
ookami-kb Jul 15, 2024
a0bddbf
wip: send token flow
Jaxiii 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
097a9e7
Merge branch 'feat/store-token-list-localdb' into token-details-page
Jaxiii Jul 15, 2024
66eb39e
fix: remove solana pkg changes
Jaxiii Jul 15, 2024
bc0d304
fix: format codec exception
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
48249e8
Merge branch 'feat/store-token-list-localdb' into token-details-page
Jaxiii Jul 16, 2024
cdda44d
refact: arg naming style
Jaxiii Jul 16, 2024
38e2d94
Merge branch 'feat/store-token-list-localdb' into token-details-page
Jaxiii Jul 16, 2024
e989cbf
wip: moving tx init
Jaxiii Jul 17, 2024
6efacdd
fix: remove future from build method
Jaxiii Jul 17, 2024
2ebf21c
Merge branch 'feat/store-token-list-localdb' into token-details-page
Jaxiii Jul 17, 2024
7ba20cb
fix: analyzer
Jaxiii Jul 17, 2024
10900c1
refact: transaction repo init
Jaxiii Jul 18, 2024
ef8ab00
refact: transaction repo init
Jaxiii Jul 18, 2024
6e9ecac
Merge branch 'token-details-page' into feat/send-token
Jaxiii Jul 18, 2024
54c2dca
wip: send token flow
Jaxiii Jul 19, 2024
8ec0101
wip: send token flow
Jaxiii Jul 19, 2024
9536499
minor upd
justinenerio Jul 23, 2024
14bbe6d
refactor: polish
Jaxiii Jul 26, 2024
841a0a1
refact: remove async cache
Jaxiii Jul 26, 2024
b1bb454
refactor to services
justinenerio Jul 26, 2024
3417fcc
upd
justinenerio Jul 26, 2024
6ff06c2
Merge branch 'feat/store-token-list-localdb' into token-details-page
Jaxiii Jul 26, 2024
e6d9ff4
refact: remove unused wrapper
Jaxiii Jul 26, 2024
9dfd8e6
fix: remove unused var
Jaxiii Jul 26, 2024
e5c69c7
Merge branch 'token-details-page' into feat/send-token
Jaxiii Jul 26, 2024
2f9716a
fix: remove unused param
Jaxiii Jul 26, 2024
d32dd02
fix: remove unused param
Jaxiii Jul 26, 2024
a37ab9c
Merge branch 'token-details-page' into feat/send-token
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
1a7e6e6
Merge branch 'feat/store-token-list-localdb' into token-details-page
Jaxiii Jul 31, 2024
7612dc7
add schema
Jaxiii Jul 31, 2024
2f74a10
Merge branch 'token-details-page' into feat/send-token
Jaxiii Aug 1, 2024
37e3d39
upd
ookami-kb Aug 1, 2024
9851a7b
upd
ookami-kb Aug 1, 2024
052ac50
fix: watch activity
Jaxiii Aug 1, 2024
3b63a27
fix: linter
Jaxiii Aug 2, 2024
38f1f9c
fix: remove unused import
Jaxiii Aug 2, 2024
da1b61c
Merge branch 'feat/store-token-list-localdb' into token-details-page
Jaxiii Aug 2, 2024
19b1cea
Merge branch 'token-details-page' into feat/send-token
Jaxiii Aug 2, 2024
eed63b8
feat: quant input validation
Jaxiii Aug 2, 2024
ba3f144
feat: input locale
Jaxiii Aug 2, 2024
6ddbff3
feat: usdc equivalent token value
Jaxiii Aug 2, 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
41fb4b1
refact: validate func
Jaxiii Aug 3, 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
ad110f1
Merge branch 'feat/store-token-list-localdb' into token-details-page
Jaxiii Aug 14, 2024
a4ee191
refact: rmv single upd
Jaxiii Aug 14, 2024
864eb41
upd schema
Jaxiii Aug 14, 2024
b30eb5a
Merge branch 'token-details-page' into feat/send-token
Jaxiii Aug 14, 2024
dd363aa
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Aug 15, 2024
0248745
Merge branch 'feat/store-token-list-localdb' into token-details-page
Jaxiii Aug 15, 2024
ed9941c
Merge branch 'token-details-page' into feat/send-token
Jaxiii Aug 15, 2024
d5a87d5
upd
Jaxiii Aug 15, 2024
5b37614
upd
Jaxiii Aug 15, 2024
17b8408
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Aug 16, 2024
327699a
upd
Jaxiii Aug 16, 2024
1e7b428
Merge branch 'feat/store-token-list-localdb' into token-details-page
Jaxiii Aug 16, 2024
e9c1539
Merge branch 'token-details-page' into feat/send-token
Jaxiii Aug 16, 2024
a6a05df
Merge branch 'master' into feat/store-token-list-localdb
Jaxiii Aug 21, 2024
02e6658
Merge branch 'feat/store-token-list-localdb' into token-details-page
Jaxiii Aug 21, 2024
1721e07
upd schema
Jaxiii Aug 21, 2024
96c5f0f
Merge branch 'token-details-page' into feat/send-token
Jaxiii Aug 21, 2024
41effb2
wip
Jaxiii Aug 23, 2024
7e267c4
wip
Jaxiii Aug 23, 2024
99caf28
wip
Jaxiii Aug 23, 2024
9fa7535
wip
Jaxiii Aug 23, 2024
a662631
fix cycle
Jaxiii Aug 23, 2024
f02ec0d
upd schemas
Jaxiii Aug 23, 2024
1f98191
Merge branch 'feat/store-token-list-localdb' into token-details-page
Jaxiii Aug 23, 2024
47fcc5f
Merge branch 'token-details-page' into feat/send-token
Jaxiii Aug 23, 2024
345a0c1
upd schema
Jaxiii Aug 23, 2024
02430a6
Merge branch 'token-details-page' into feat/send-token
Jaxiii Aug 23, 2024
d4b7ee4
upd
Jaxiii Aug 23, 2024
23b2941
Merge branch 'token-details-page' into feat/send-token
Jaxiii Aug 23, 2024
c40f85f
upd
Jaxiii Aug 23, 2024
70c3ee8
Merge branch 'token-details-page' into feat/send-token
Jaxiii Aug 23, 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.
46 changes: 42 additions & 4 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 = 56;
const int latestVersion = 58;

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

@lazySingleton
Expand Down Expand Up @@ -116,19 +117,16 @@ class MyDatabase extends _$MyDatabase {
if (from < 51) {
await m.addColumn(transactionRows, transactionRows.amount);
}

if (from < 52) {
await m.createTable(tokenBalanceRows);
}

if (from < 53) {
await m.addColumn(onRampOrderRows, onRampOrderRows.authToken);
await m.addColumn(onRampOrderRows, onRampOrderRows.moreInfoUrl);
await m.addColumn(onRampOrderRows, onRampOrderRows.stellarTxHash);
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 @@ -158,6 +156,12 @@ class MyDatabase extends _$MyDatabase {
if (from < 56) {
await m.createTable(conversionRatesRows);
}
if (from < 57) {
await m.createTable(tokenRows);
}
if (from < 58) {
await m.addColumn(transactionRows, transactionRows.tokenAddress);
}
},
);
}
Expand Down Expand Up @@ -283,6 +287,7 @@ class TransactionRows extends Table {

TextColumn get id => text()();
DateTimeColumn get created => dateTime().nullable()();
TextColumn get tokenAddress => text()();
TextColumn get encodedTx => text()();
IntColumn get status => intEnum<TxCommonStatus>()();
IntColumn get amount => integer().nullable()();
Expand Down Expand Up @@ -325,3 +330,36 @@ 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};
}

class TagsConverter extends TypeConverter<List<String>, String> {
const TagsConverter();

@override
List<String> fromSql(String fromDb) {
if (fromDb.isEmpty) return [];

return fromDb.split(',');
}

@override
String toSql(List<String> value) {
if (value.isEmpty) return '';

return value.join(',');
}
}
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
@@ -1,31 +1,49 @@
import 'dart:async';

import 'package:async/async.dart';
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:get_it/get_it.dart';
import 'package:injectable/injectable.dart';
import 'package:intl/intl.dart';
import 'package:rxdart/rxdart.dart';
import 'package:solana/base58.dart';
import 'package:solana/dto.dart' hide Transaction;
import 'package:solana/encoder.dart';
import 'package:solana/solana.dart';

import '../../../data/db/db.dart';
import '../../../di.dart';
import '../../../utils/async_cache.dart';
import '../../accounts/auth_scope.dart';
import '../../accounts/models/ec_wallet.dart';
import '../../currency/models/amount.dart';
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 '../../tokens/data/token_repository.dart';
import '../../tokens/token.dart';
import '../../transaction_request/service/tr_service.dart';
import '../models/activity.dart';
import '../models/transaction.dart';
import 'activity_builder.dart';

@injectable
part '../services/tx_updater.dart';

@Singleton(scope: authScope)
class TransactionRepository {
const TransactionRepository(this._db, this._tokens);
TransactionRepository(this._db, this._client, this._wallet) {
update();
}

final SolanaClient _client;
final ECWallet _wallet;
final MyDatabase _db;
final TokenList _tokens;

final AsyncCache<void> _callCache = AsyncCache.ephemeral();

Stream<IList<String>> watchAll() {
final query = _db.select(_db.transactionRows)
Expand All @@ -34,6 +52,38 @@ class TransactionRepository {
return query.map((row) => row.id).watch().map((event) => event.toIList());
}

Stream<IList<String>> watchByAddress(String tokenAddress) {
final query = _db.select(_db.transactionRows)
..where((t) => t.tokenAddress.equals(tokenAddress))
..orderBy([(t) => OrderingTerm.desc(t.created)]);

return query.map((row) => row.id).watch().map((event) => event.toIList());
}

Stream<Map<String, IList<TxCommon>>> watchGroupedByDate(String tokenAddress) {
final query = _db.select(_db.transactionRows)
..where((t) => t.tokenAddress.equals(tokenAddress))
..orderBy([(t) => OrderingTerm.desc(t.created)]);

return query.watch().asyncMap((rows) async {
final grouped = <String, IList<TxCommon>>{};
for (final row in rows) {
final model = await row.toModel();
final created = model.created;
if (created != null) {
final date = DateFormat('yyyy-MM-dd').format(created);
grouped.update(
date,
(list) => list.add(model),
ifAbsent: () => IList([model]),
);
}
}

return grouped;
});
}

Stream<IList<String>> watchCount(int count) {
final query = _db.select(_db.transactionRows)
..limit(count)
Expand All @@ -46,29 +96,19 @@ class TransactionRepository {
final query = _db.select(_db.transactionRows)
..where((tbl) => tbl.id.equals(id));

return query.watchSingle().asyncExpand((row) => _match(row.toModel()));
}

Future<void> saveAll(
Iterable<TxCommon> txs, {
required bool clear,
}) {
Future<void> save() => _db.batch(
(batch) => batch.insertAll(
_db.transactionRows,
txs.map((e) => e.toRow()),
mode: InsertMode.insertOrReplace,
),
return query.watchSingle().asyncMap(
(row) async => row.toModel().then((value) => _match(value).first),
);

return clear
? _db.transaction(() async {
await _db.delete(_db.transactionRows).go();
await save();
})
: save();
}

Future<void> saveAll(Iterable<TxCommon> txs) => _db.batch(
(batch) => batch.insertAll(
_db.transactionRows,
txs.map((e) => e.toRow()),
mode: InsertMode.insertOrReplace,
),
);

Future<String?> mostRecentTxId() async {
final query = _db.select(_db.transactionRows)
..orderBy([(t) => OrderingTerm.desc(t.created)])
Expand Down Expand Up @@ -96,13 +136,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 Expand Up @@ -149,20 +189,29 @@ class TransactionRepository {
}

extension TransactionRowExt on TransactionRow {
TxCommon toModel() => TxCommon(
SignedTx.decode(encodedTx),
created: created,
status: status,
amount: amount?.let(
(it) => CryptoAmount(value: it, cryptoCurrency: Currency.usdc),
),
);
Future<TxCommon> toModel() =>
sl<TokenRepository>().getToken(tokenAddress).letAsync(
(e) => TxCommon(
SignedTx.decode(encodedTx),
created: created,
status: status,
amount: amount?.let(
(it) => CryptoAmount(
value: it,
cryptoCurrency: CryptoCurrency(
token: e ?? Token.unk,
),
),
),
),
);
}

extension on TxCommon {
TransactionRow toRow() => TransactionRow(
id: tx.id,
created: created,
tokenAddress: amount?.cryptoCurrency.token.address ?? Token.unk.address,
encodedTx: tx.encode(),
status: status,
amount: amount?.value,
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
Loading
Loading