Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ jobs:
const kShopInBitPartnerSecret = "";
const kCakePayApiToken = "";
const kExolixApiKey = "";
const kLetsExchangeId = "";
const kLetsExchangeToken = "";
const kCypherGoatApiKey = "";
const kCypherGoatAffiliate = "";
EOF
fi

Expand Down
122 changes: 71 additions & 51 deletions lib/pages/add_wallet_views/add_token_view/edit_wallet_tokens_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:isar_community/isar.dart';

import '../../../app_config.dart';
import '../../../db/isar/main_db.dart';
import '../../../models/isar/models/ethereum/eth_contract.dart';
import '../../../models/isar/models/solana/sol_contract.dart';
Expand Down Expand Up @@ -80,6 +81,7 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
final List<AddTokenListElementData> tokenEntities = [];

final bool isDesktop = Util.isDesktop;
final bool isCampfire = AppConfig.appName == "Campfire";

List<AddTokenListElementData> filter(
String text,
Expand All @@ -100,11 +102,10 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
}

Future<void> onNextPressed() async {
final selectedTokens =
tokenEntities
.where((e) => e.selected)
.map((e) => e.token.address)
.toList();
final selectedTokens = tokenEntities
.where((e) => e.selected)
.map((e) => e.token.address)
.toList();

final wallet = ref.read(pWallets).getWallet(widget.walletId);

Expand Down Expand Up @@ -177,7 +178,9 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
tokenEntities.add(
AddTokenListElementData(contract!)..selected = true,
);
tokenEntities.sort((a, b) => a.token.name.compareTo(b.token.name));
tokenEntities.sort(
(a, b) => a.token.name.compareTo(b.token.name),
);
}
});
}
Expand All @@ -199,9 +202,7 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
),
);
} else {
final result = await Navigator.of(
context,
).pushNamed(
final result = await Navigator.of(context).pushNamed(
AddCustomSolanaTokenView.routeName,
arguments: widget.walletId,
);
Expand All @@ -228,9 +229,7 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
if (tokenEntities
.where((e) => e.token.address == token!.address)
.isEmpty) {
tokenEntities.add(
AddTokenListElementData(token!)..selected = true,
);
tokenEntities.add(AddTokenListElementData(token!)..selected = true);
tokenEntities.sort((a, b) => a.token.name.compareTo(b.token.name));
}
});
Expand All @@ -244,6 +243,14 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
_searchFocusNode = FocusNode();

final wallet = ref.read(pWallets).getWallet(widget.walletId);
final walletContracts = ref.read(pWalletTokenAddresses(widget.walletId));
final shouldMarkAsSelectedContracts = [
...walletContracts,
...(widget.contractsToMarkSelected ?? []),
];
final selectedContractAddresses = shouldMarkAsSelectedContracts
.map((e) => e.toLowerCase())
.toSet();

if (wallet is SolanaWallet) {
final contracts = MainDB.instance
Expand All @@ -266,29 +273,36 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
.getEthContracts()
.sortByName()
.findAllSync();

if (contracts.isEmpty) {
contracts.addAll(DefaultTokens.list);
final defaults = DefaultTokens.forApp(AppConfig.appName);
final existingAddresses = contracts
.map((e) => e.address.toLowerCase())
.toSet();
final missingDefaults = defaults
.where((token) => existingAddresses.add(token.address.toLowerCase()))
.toList();

if (missingDefaults.isNotEmpty) {
contracts.addAll(missingDefaults);
MainDB.instance
.putEthContracts(contracts)
.putEthContracts(missingDefaults)
.then(
(_) => ref.read(priceAnd24hChangeNotifierProvider).updatePrice(),
);
}

contracts.retainWhere(
(token) =>
DefaultTokens.isAllowedForApp(AppConfig.appName, token) ||
selectedContractAddresses.contains(token.address.toLowerCase()),
);

tokenEntities.addAll(contracts.map((e) => AddTokenListElementData(e)));
}

// Get token addresses.
final walletContracts = ref.read(pWalletTokenAddresses(widget.walletId));

final shouldMarkAsSelectedContracts = [
...walletContracts,
...(widget.contractsToMarkSelected ?? []),
];

for (final e in tokenEntities) {
e.selected = shouldMarkAsSelectedContracts.contains(e.token.address);
e.selected = wallet is EthereumWallet
? selectedContractAddresses.contains(e.token.address.toLowerCase())
: shouldMarkAsSelectedContracts.contains(e.token.address);
}

super.initState();
Expand Down Expand Up @@ -318,7 +332,7 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
walletName,
style: STextStyles.desktopSubtitleH2(context),
),
trailing: widget.contractsToMarkSelected == null
trailing: widget.contractsToMarkSelected == null && !isCampfire
? Padding(
padding: const EdgeInsets.only(right: 24),
child: SizedBox(
Expand Down Expand Up @@ -410,14 +424,15 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Row(
children: [
Expanded(
child: SecondaryButton(
label: "Add custom token",
buttonHeight: ButtonHeight.l,
onPressed: _addToken,
if (!isCampfire)
Expanded(
child: SecondaryButton(
label: "Add custom token",
buttonHeight: ButtonHeight.l,
onPressed: _addToken,
),
),
),
const SizedBox(width: 16),
if (!isCampfire) const SizedBox(width: 16),
Expanded(
child: PrimaryButton(
label: "Done",
Expand Down Expand Up @@ -526,28 +541,33 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
},
),
actions: [
Padding(
padding: const EdgeInsets.only(top: 10, bottom: 10, right: 20),
child: AspectRatio(
aspectRatio: 1,
child: AppBarIconButton(
size: 36,
shadows: const [],
color: Theme.of(
context,
).extension<StackColors>()!.background,
icon: SvgPicture.asset(
Assets.svg.circlePlusFilled,
if (!isCampfire)
Padding(
padding: const EdgeInsets.only(
top: 10,
bottom: 10,
right: 20,
),
child: AspectRatio(
aspectRatio: 1,
child: AppBarIconButton(
size: 36,
shadows: const [],
color: Theme.of(
context,
).extension<StackColors>()!.topNavIconPrimary,
width: 20,
height: 20,
).extension<StackColors>()!.background,
icon: SvgPicture.asset(
Assets.svg.circlePlusFilled,
color: Theme.of(
context,
).extension<StackColors>()!.topNavIconPrimary,
width: 20,
height: 20,
),
onPressed: _addToken,
),
onPressed: _addToken,
),
),
),
],
),
body: SafeArea(
Expand Down Expand Up @@ -620,7 +640,7 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
child: AddTokenList(
walletId: widget.walletId,
items: filter(_searchTerm, tokenEntities),
addFunction: _addToken,
addFunction: isCampfire ? null : _addToken,
),
),
const SizedBox(height: 16),
Expand Down
Loading
Loading