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
12 changes: 0 additions & 12 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ jobs:
run: |
if [ -n "$CHANGE_NOW" ]; then
echo "$CHANGE_NOW" | base64 --decode > lib/external_api_keys.dart
else
cat > lib/external_api_keys.dart << 'EOF'
const String kChangeNowApiKey = "";
const String kSimpleSwapApiKey = "";
const String kNanswapApiKey = "";
const String kNanoSwapRpcApiKey = "";
const String kWizSwapApiKey = "";
const kShopInBitAccessKey = "";
const kShopInBitPartnerSecret = "";
const kCakePayApiToken = "";
const kExolixApiKey = "";
EOF
fi

- name: Ensure app config for tests
Expand Down
16 changes: 16 additions & 0 deletions assets/images/rsfiro.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 19 additions & 1 deletion lib/app_config.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
// ignore: unused_import
import 'dart:io';

import 'models/isar/models/ethereum/eth_contract.dart';
import 'utilities/default_eth_tokens.dart';
import 'wallets/crypto_currency/crypto_currency.dart';
import 'wallets/crypto_currency/intermediate/frost_currency.dart';

part 'app_config.g.dart';

enum AppFeature { themeSelection, buy, swap, tor, shopinBit, cakePay }
enum AppFeature {
themeSelection,
buy,
swap,
tor,
shopinBit,
cakePay,
addCustomTokens,
limitedEthTokenDefaults,
}

abstract class AppConfig {
static const appName = _prefix + _separator + suffix;
Expand All @@ -28,6 +39,13 @@ abstract class AppConfig {

static List<CryptoCurrency> get coins => _supportedCoins;

static List<EthContract> get defaultEthTokens {
if (coins.whereType<Ethereum>().isEmpty) return const [];
return hasFeature(AppFeature.limitedEthTokenDefaults)
? DefaultTokens.limited
: DefaultTokens.list;
}

static ({String from, String fromFuzzyNet, String to, String toFuzzyNet})
get swapDefaults => _swapDefaults;

Expand Down
121 changes: 63 additions & 58 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,9 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
final List<AddTokenListElementData> tokenEntities = [];

final bool isDesktop = Util.isDesktop;
final bool canAddCustomTokens = AppConfig.hasFeature(
AppFeature.addCustomTokens,
);

List<AddTokenListElementData> filter(
String text,
Expand All @@ -100,11 +104,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 All @@ -119,13 +122,11 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
Navigator.of(context).pop(42);
} else {
if (isDesktop) {
Navigator.of(
context,
).popUntil(ModalRoute.withName(DesktopHomeView.routeName));
Navigator.of(context)
.popUntil(ModalRoute.withName(DesktopHomeView.routeName));
} else {
await Navigator.of(
context,
).pushNamedAndRemoveUntil(HomeView.routeName, (route) => false);
await Navigator.of(context)
.pushNamedAndRemoveUntil(HomeView.routeName, (route) => false);
}
if (mounted) {
unawaited(
Expand Down Expand Up @@ -160,9 +161,8 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
),
);
} else {
final result = await Navigator.of(
context,
).pushNamed(AddCustomTokenView.routeName);
final result = await Navigator.of(context)
.pushNamed(AddCustomTokenView.routeName);
contract = result as EthContract?;
}

Expand All @@ -177,7 +177,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 +201,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 +228,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 Down Expand Up @@ -267,8 +265,7 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
.sortByName()
.findAllSync();

if (contracts.isEmpty) {
contracts.addAll(DefaultTokens.list);
if (DefaultTokens.seedIfEmpty(contracts, AppConfig.defaultEthTokens)) {
MainDB.instance
.putEthContracts(contracts)
.then(
Expand Down Expand Up @@ -318,7 +315,8 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
walletName,
style: STextStyles.desktopSubtitleH2(context),
),
trailing: widget.contractsToMarkSelected == null
trailing:
widget.contractsToMarkSelected == null && canAddCustomTokens
? Padding(
padding: const EdgeInsets.only(right: 24),
child: SizedBox(
Expand Down Expand Up @@ -410,14 +408,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 (canAddCustomTokens)
Expanded(
child: SecondaryButton(
label: "Add custom token",
buttonHeight: ButtonHeight.l,
onPressed: _addToken,
),
),
),
const SizedBox(width: 16),
if (canAddCustomTokens) const SizedBox(width: 16),
Expanded(
child: PrimaryButton(
label: "Done",
Expand Down Expand Up @@ -448,9 +447,8 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
_searchTerm = value;
});
},
style: STextStyles.desktopTextMedium(
context,
).copyWith(height: 2),
style: STextStyles.desktopTextMedium(context)
.copyWith(height: 2),
decoration:
standardInputDecoration(
"Search",
Expand Down Expand Up @@ -505,7 +503,9 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
child: AddTokenList(
walletId: widget.walletId,
items: filter(_searchTerm, tokenEntities),
addFunction: isDesktop ? null : _addToken,
addFunction: isDesktop || !canAddCustomTokens
? null
: _addToken,
),
),
const SizedBox(height: 12),
Expand All @@ -516,38 +516,43 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
} else {
return Background(
child: Scaffold(
backgroundColor: Theme.of(
context,
).extension<StackColors>()!.background,
backgroundColor: Theme.of(context)
.extension<StackColors>()!
.background,
appBar: AppBar(
leading: AppBarBackButton(
onPressed: () {
Navigator.of(context).pop();
},
),
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,
color: Theme.of(
context,
).extension<StackColors>()!.topNavIconPrimary,
width: 20,
height: 20,
if (canAddCustomTokens)
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,
color: Theme.of(context)
.extension<StackColors>()!
.topNavIconPrimary,
width: 20,
height: 20,
),
onPressed: _addToken,
),
onPressed: _addToken,
),
),
),
],
),
body: SafeArea(
Expand Down Expand Up @@ -620,7 +625,7 @@ class _EditWalletTokensViewState extends ConsumerState<EditWalletTokensView> {
child: AddTokenList(
walletId: widget.walletId,
items: filter(_searchTerm, tokenEntities),
addFunction: _addToken,
addFunction: canAddCustomTokens ? _addToken : null,
),
),
const SizedBox(height: 16),
Expand Down
Loading
Loading