Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b804c22
WIP: activate stellar addresses
AlaaElattar May 5, 2025
d8e54d6
WIP: trying to fix context issue
AlaaElattar May 5, 2025
85cbc76
WIP: trying to fix context issue
AlaaElattar May 6, 2025
0e0f3a9
WIP: remove activation while adding wallet && add activation address …
AlaaElattar May 6, 2025
87d6c0c
updated price conversion
AlaaElattar May 6, 2025
06a029c
apply pr comments
AlaaElattar May 6, 2025
4a67279
update activation fee to be const
AlaaElattar May 7, 2025
a1d3ca2
WIP: apply pr comments
AlaaElattar May 7, 2025
9a2e215
add balance with wallet name in dropdown
AlaaElattar May 8, 2025
75a3da4
update validation
AlaaElattar May 8, 2025
162a308
handle balance if trades are zero
AlaaElattar May 8, 2025
f817c81
handle case when account already activated
AlaaElattar May 8, 2025
8e01f0d
fix failed workflow
AlaaElattar May 8, 2025
383dcb9
handle tft trustline
AlaaElattar May 11, 2025
8b09efe
fix fees to be in xlm
AlaaElattar May 11, 2025
f4cc756
add button inside assets card
AlaaElattar May 11, 2025
63bc1fa
update stellar balance to represent if activated or no having tft tru…
AlaaElattar May 11, 2025
a06aff4
Update app/lib/widgets/wallets/balance_tile.dart
AlaaElattar May 11, 2025
f31ba49
Update app/lib/widgets/wallets/wallet_card.dart
AlaaElattar May 11, 2025
e104265
Update app/lib/widgets/wallets/activate_wallet.dart
AlaaElattar May 11, 2025
a62f00e
Update app/lib/widgets/wallets/activate_wallet.dart
AlaaElattar May 11, 2025
b999d32
Update app/lib/widgets/wallets/activate_wallet.dart
AlaaElattar May 11, 2025
01aabc7
fix stellarBalance check in all screens
AlaaElattar May 11, 2025
9f38604
update stellarBalance conditions
AlaaElattar May 11, 2025
d534c31
update condition for consistency
AlaaElattar May 11, 2025
5252cc6
Merge branch 'development' into developement_activate_stellar
AlaaElattar May 11, 2025
68b42ae
fix condition in farm details
AlaaElattar May 11, 2025
fa8683f
fix init daily wallet condiotion
AlaaElattar May 11, 2025
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
5 changes: 5 additions & 0 deletions app/lib/helpers/flags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ class Flags {
await Flags().hasFlagValueByFeatureName('council-member');
Globals().registrarURL =
(await Flags().getFlagValueByFeatureName('registrar-url')).toString();

Globals().activationServiceAddress = (await Flags()
.getFlagValueByFeatureName('activation-service-address'))
.toString();

}

Future<bool> hasFlagValueByFeatureName(String name) async {
Expand Down
6 changes: 3 additions & 3 deletions app/lib/helpers/globals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import 'package:threebotlogin/models/payment_request.dart';

class NoAnimationTabController extends TabController {
NoAnimationTabController(
{super.initialIndex,
required super.length,
required super.vsync});
{super.initialIndex, required super.length, required super.vsync});

@override
void animateTo(int value,
Expand Down Expand Up @@ -76,6 +74,8 @@ class Globals {
int emailSentOn = 0;
int emailMinutesCoolDown = 1;

String activationServiceAddress = '';

ValueNotifier<bool> hidePhoneButton = ValueNotifier(false);

static final Globals _singleton = Globals._internal();
Expand Down
4 changes: 2 additions & 2 deletions app/lib/screens/farm_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class _FarmDetailsState extends State<FarmDetails> {

try {
final balance = await getBalanceByAccountId(address);
if (balance == '-1') {
if (double.parse(balance) <= -1) {
setState(() {
stellarAddressError = 'Wallet not activated on stellar';
});
Expand Down Expand Up @@ -120,7 +120,7 @@ class _FarmDetailsState extends State<FarmDetails> {

try {
final balance = await getBalanceByAccountId(newAddress);
if (balance == '-1') {
if (double.parse(balance) <= -1) {
if (context.mounted) {
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
Expand Down
5 changes: 3 additions & 2 deletions app/lib/screens/wallets/bridge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class _WalletBridgeScreenState extends ConsumerState<WalletBridgeScreen> {
return false;
}
final toAddrBalance = await Stellar.getBalanceByAccountId(toAddress);
if (toAddrBalance == '-1') {
if (double.parse(toAddrBalance) <= -1) {
toAddressError = 'Address must be active and have TFT trustline';
return false;
}
Expand Down Expand Up @@ -209,7 +209,8 @@ class _WalletBridgeScreenState extends ConsumerState<WalletBridgeScreen> {
@override
Widget build(BuildContext context) {
List<Wallet> wallets = ref.read(walletsNotifier);
final bool disableDeposit = widget.wallet.stellarBalance == '-1';
final bool disableDeposit =
double.parse(widget.wallet.stellarBalance) <= -1;
if (disableDeposit && !isWithdraw) {
onTransactionChange(BridgeOperation.Withdraw);
}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/screens/wallets/receive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class _WalletReceiveScreenState extends State<WalletReceiveScreen> {

@override
Widget build(BuildContext context) {
final bool hideStellar = widget.wallet.stellarBalance == '-1';
final bool hideStellar = double.parse(widget.wallet.stellarBalance) <= -1;
if (hideStellar) {
onChangeChain(ChainType.TFChain);
}
Expand Down
6 changes: 3 additions & 3 deletions app/lib/screens/wallets/send.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ class _WalletSendScreenState extends ConsumerState<WalletSendScreen> {
wallets.where((wallet) => wallet.stellarAddress == toAddress);
final Wallet? wallet =
matchingWallets.isNotEmpty ? matchingWallets.first : null;
if (wallet != null && wallet.stellarBalance == '-1') {
if (wallet != null && double.parse(wallet.stellarBalance) <= -1) {
setState(() {
toAddressError = 'Wallet not activated on stellar';
});
return false;
} else {
final balance = await Stellar.getBalanceByAccountId(toAddress);
if (balance == '-1') {
if (double.parse(balance) <= -1) {
setState(() {
toAddressError = 'Wallet not activated on stellar';
});
Expand Down Expand Up @@ -218,7 +218,7 @@ class _WalletSendScreenState extends ConsumerState<WalletSendScreen> {

@override
Widget build(BuildContext context) {
final bool hideStellar = widget.wallet.stellarBalance == '-1';
final bool hideStellar = double.parse(widget.wallet.stellarBalance) <= -1;
if (hideStellar && chainType == ChainType.Stellar) {
onChangeChain(ChainType.TFChain);
}
Expand Down
4 changes: 2 additions & 2 deletions app/lib/screens/wallets/transactions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class _WalletTransactionsWidgetState extends State<WalletTransactionsWidget> {
@override
void initState() {
super.initState();
if (widget.wallet.stellarBalance != '-1') {
if (double.parse(widget.wallet.stellarBalance) > -1) {
_pagingController.addPageRequestListener(_listTransactions);
}
}
Expand All @@ -80,7 +80,7 @@ class _WalletTransactionsWidgetState extends State<WalletTransactionsWidget> {

@override
Widget build(BuildContext context) {
if (widget.wallet.stellarBalance == '-1') {
if (double.parse(widget.wallet.stellarBalance) <= -1) {
return Center(
child: Text(
'No transactions yet.',
Expand Down
24 changes: 21 additions & 3 deletions app/lib/screens/wallets/wallet_assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:threebotlogin/screens/wallets/bridge.dart';
import 'package:threebotlogin/screens/wallets/receive.dart';
import 'package:threebotlogin/screens/wallets/send.dart';
import 'package:threebotlogin/services/stellar_service.dart' as Stellar;
import 'package:threebotlogin/widgets/wallets/activate_wallet.dart';
import 'package:threebotlogin/widgets/wallets/arrow_inward.dart';
import 'package:threebotlogin/widgets/wallets/balance_tile.dart';

Expand Down Expand Up @@ -59,6 +60,18 @@ class _WalletAssetsWidgetState extends State<WalletAssetsWidget> {
super.dispose();
}

_openActivateStellarOverlay() {
showModalBottomSheet(
isScrollControlled: true,
useSafeArea: true,
isDismissible: false,
constraints: const BoxConstraints(maxWidth: double.infinity),
context: context,
builder: (ctx) => ActivateWalletWidget(
wallet: widget.wallet,
));
}

@override
Widget build(BuildContext context) {
List<Widget> vestWidgets = [];
Expand Down Expand Up @@ -210,9 +223,14 @@ class _WalletAssetsWidgetState extends State<WalletAssetsWidget> {
balance: formatAmount(widget.wallet.tfchainBalance),
loading: tfchainBalaceLoading,
),
const SizedBox(
height: 20,
),
const SizedBox(height: 10),
if (double.parse(widget.wallet.stellarBalance) <= -1)
WalletBalanceTileWidget(
name: ChainType.Stellar,
balance: widget.wallet.stellarBalance,
loading: false,
onActivate: _openActivateStellarOverlay,
),
...vestWidgets
],
),
Expand Down
57 changes: 55 additions & 2 deletions app/lib/services/stellar_service.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:stellar_client/models/transaction.dart';
import 'package:stellar_client/models/vesting_account.dart';
import 'package:stellar_client/stellar_client.dart';
import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart';
import 'package:threebotlogin/helpers/logger.dart';
import 'package:http/http.dart' as http;

bool isValidStellarSecret(String seed) {
try {
Expand Down Expand Up @@ -37,7 +39,10 @@ Future<String> getBalanceByClient(Client client) async {
}
} catch (e) {
logger.i("Couldn't load the account balance due to $e");
// -2 means that the account not activated on stellar
return '-2';
}
// -1 means that account activated but no TFT trustline
return '-1';
}

Expand Down Expand Up @@ -77,9 +82,9 @@ Future<void> transfer(String secret, String dest, String amount,
);
}

Future<void> initialize(String secret) async {
Future<bool> initialize(String secret) async {
final client = Client(NetworkType.PUBLIC, secret);
await client.activateThroughThreefoldService();
return await client.activateThroughThreefoldService();
}

Future<String> getBalanceByAccountId(String accountId) async {
Expand All @@ -94,6 +99,54 @@ Future<String> getBalanceByAccountId(String accountId) async {
}
} catch (e) {
logger.i("Couldn't load the account balance due to $e");
return '-2';
}
return '-1';
}

Future<int> getTFTPriceFromXLM() async {
const String baseUrl = 'https://horizon.stellar.org';
const String counterAssetCode = 'TFT';
const String counterAssetIssuer =
'GBOVQKJYHXRR3DX6NOX2RRYFRCUMSADGDESTDNBDS6CDVLGVESRTAC47';
final String requestUrl = '$baseUrl/trades?base_asset_type=native'
'&counter_asset_type=credit_alphanum4'
'&counter_asset_code=$counterAssetCode'
'&counter_asset_issuer=$counterAssetIssuer'
'&order=desc&limit=1';

try {
final response = await http.get(Uri.parse(requestUrl));

if (response.statusCode == 200) {
final data = jsonDecode(response.body);
final List<dynamic> trades = data['_embedded']?['records'] ?? [];

if (trades.isNotEmpty) {
final trade = trades[0];
final double baseAmount = double.parse(trade['base_amount']);
final double counterAmount = double.parse(trade['counter_amount']);

final double pricePerTFT = counterAmount / baseAmount;
logger.i('Last traded price for 1 XLM in TFT: $pricePerTFT');
final int roundedPrice = pricePerTFT.ceil();

return roundedPrice;
} else {
logger.i('No recent trades found.');
return 0;
Comment thread
AlaaElattar marked this conversation as resolved.
}
} else {
logger.e('Error fetching last traded price: ${response.statusCode}');
throw Exception('Error getting price');
}
} catch (e) {
logger.e('Error: $e');
throw Exception('Error getting price');
}
}

Future<bool> addTFTTrustline(String secret, String assetCode) async {
final client = Client(NetworkType.PUBLIC, secret);
return await client.addTrustLineThroughThreefoldService(assetCode);
}
15 changes: 14 additions & 1 deletion app/lib/services/tfchain_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Future<Map<String, List<Proposal>>> getProposals() async {
return proposals;
} catch (e) {
throw Exception('Failed to get DAO proposals due to $e');
} finally{
} finally {
if (proposals != null) {
await client.disconnect();
}
Expand Down Expand Up @@ -324,3 +324,16 @@ Future<Votes> getCouncilProposalVotes(String chainUrl, String hash) async {
await client.disconnect();
}
}

Future<int> getTFTPrice(String chainUrl) async {
final client = TFChain.QueryClient(chainUrl);
try {
await client.connect();
final price = await client.price.get();
return price;
} catch (e) {
throw Exception('Failed to get TFT price due to $e');
} finally {
await client.disconnect();
}
}
2 changes: 1 addition & 1 deletion app/lib/widgets/add_farm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class _NewFarmState extends State<NewFarm> {
});
return false;
}
if (_selectedWallet!.stellarBalance == '-1') {
if (double.parse(_selectedWallet!.stellarBalance) <= -1) {
setState(() {
walletError = 'Wallet not activated on stellar';
});
Expand Down
Loading