Skip to content

Commit a1d3ca2

Browse files
committed
WIP: apply pr comments
1 parent 4a67279 commit a1d3ca2

2 files changed

Lines changed: 16 additions & 26 deletions

File tree

app/lib/services/stellar_service.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ Future<void> transfer(String secret, String dest, String amount,
7979
);
8080
}
8181

82-
Future<void> initialize(String secret) async {
82+
Future<bool> initialize(String secret) async {
8383
final client = Client(NetworkType.PUBLIC, secret);
84-
await client.activateThroughThreefoldService();
84+
return await client.activateThroughThreefoldService();
8585
}
8686

8787
Future<String> getBalanceByAccountId(String accountId) async {
@@ -100,16 +100,6 @@ Future<String> getBalanceByAccountId(String accountId) async {
100100
return '-1';
101101
}
102102

103-
Future<bool> activateThroughtThreefoldService(String secret) async {
104-
final client = Client(NetworkType.PUBLIC, secret);
105-
try {
106-
return await client.activateThroughThreefoldService();
107-
} catch (e) {
108-
logger.e(e);
109-
return false;
110-
}
111-
}
112-
113103
Future<int> getTFTPriceFromXLM() async {
114104
const String baseUrl = 'https://horizon.stellar.org';
115105
const String counterAssetCode = 'TFT';

app/lib/widgets/wallets/activate_wallet.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class _ActivateWalletWidgetState extends ConsumerState<ActivateWalletWidget> {
2828
// Activation Fees in XLM
2929
static const int activationFee = 3;
3030

31-
3231
@override
3332
void initState() {
3433
super.initState();
@@ -84,7 +83,8 @@ class _ActivateWalletWidgetState extends ConsumerState<ActivateWalletWidget> {
8483
});
8584
return false;
8685
}
87-
if (double.parse(_selectedWallet!.stellarBalance) < (tftPrice * activationFee)) {
86+
if (double.parse(_selectedWallet!.stellarBalance) <
87+
(tftPrice * activationFee)) {
8888
setState(() {
8989
walletError = 'Selected wallet does not have enough TFTs';
9090
});
@@ -101,10 +101,20 @@ class _ActivateWalletWidgetState extends ConsumerState<ActivateWalletWidget> {
101101
walletError = null;
102102
});
103103

104-
final activated = await StellarService.activateThroughtThreefoldService(
105-
widget.wallet.stellarSecret);
104+
final activated =
105+
await StellarService.initialize(widget.wallet.stellarSecret);
106106
if (activated) {
107107
logger.d('Wallet activated successfully');
108+
try {
109+
logger.d('Transferring activation fee');
110+
await StellarService.transfer(
111+
_selectedWallet!.stellarSecret,
112+
Globals().activationServiceAddress,
113+
(activationFee * tftPrice).toString(),
114+
);
115+
} catch (transferError) {
116+
logger.e('Transfer error : $transferError');
117+
}
108118
await showDialog(
109119
context: context,
110120
builder: (BuildContext context) => CustomDialog(
@@ -122,16 +132,6 @@ class _ActivateWalletWidgetState extends ConsumerState<ActivateWalletWidget> {
122132
],
123133
),
124134
);
125-
try {
126-
await StellarService.transfer(
127-
_selectedWallet!.stellarSecret,
128-
Globals().activationServiceAddress,
129-
(activationFee * tftPrice).toString(),
130-
);
131-
} catch (transferError) {
132-
logger.e('Transfer error : $transferError');
133-
}
134-
135135
walletRef.reloadBalances();
136136
widget.wallet.stellarBalance = '0';
137137
Navigator.pop(context);

0 commit comments

Comments
 (0)