Skip to content

Commit

Permalink
⚡️ Improve refund management
Browse files Browse the repository at this point in the history
  • Loading branch information
redDwarf03 committed Apr 20, 2024
1 parent 4d90717 commit 493ba0f
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 188 deletions.
36 changes: 2 additions & 34 deletions lib/application/contracts/evm_htlc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,8 @@ class EVMHTLC with EVMBridgeProcessMixin, ArchethicBridgeProcessMixin {
_isERC20 = true;
}
}
} catch (e, stackTrace) {
aedappfm.sl.get<aedappfm.LogManager>().log(
'$e',
stackTrace: stackTrace,
level: aedappfm.LogLevel.error,
name: 'EVMHTLC - getAmountCurrency',
);
} catch (e) {
return (symbol: currency, isERC20: false);
}

return (symbol: currency, isERC20: _isERC20);
Expand Down Expand Up @@ -240,33 +235,6 @@ class EVMHTLC with EVMBridgeProcessMixin, ArchethicBridgeProcessMixin {
return canRefund;
}

Future<String> getTxRefund() async {
/*final evmWalletProvider = aedappfm.sl.get<EVMWalletProvider>();
await evmWalletProvider.eth!.rawRequest(
'eth_getFilterLogs',
params: [
htlcContractAddress,
JSrawRequestParams(chainId: '0x${chainId.toRadixString(16)}'),
],
);
final contractHTLC =
await getDeployedContract(contractNameHTLCBase, htlcContractAddress);
final events = await web3Client!.getLogs(
FilterOptions.events(
contract: contractHTLC,
event: contractHTLC.event('Refunded'),
),
);
if (events.isEmpty || events[0].address == null) {
return '';
}
return events[0].address!.hex;*/
return '';
}

Future<int> getStatus() async {
final contractHTLC =
await getDeployedContract(contractNameHTLCBase, htlcContractAddressEVM);
Expand Down
13 changes: 3 additions & 10 deletions lib/application/contracts/evm_htlc_erc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ class EVMHTLCERC with EVMBridgeProcessMixin {
);
}

Future<aedappfm.Result<({double fee, bool? isChargeable}), aedappfm.Failure>>
getFee() async {
Future<aedappfm.Result<double, aedappfm.Failure>> getFee() async {
return aedappfm.Result.guard(
() async {
try {
Expand All @@ -206,15 +205,9 @@ class EVMHTLCERC with EVMBridgeProcessMixin {

final BigInt fee = feeMap[0];
final etherAmount = EtherAmount.fromBigInt(EtherUnit.wei, fee);
return (
fee: etherAmount.getValueInUnit(EtherUnit.ether),
isChargeable: true,
);
return etherAmount.getValueInUnit(EtherUnit.ether);
} catch (e) {
return (
fee: 0.0,
isChargeable: false,
);
return 0.0;
}
},
);
Expand Down
13 changes: 3 additions & 10 deletions lib/application/contracts/evm_htlc_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ class EVMHTLCNative with EVMBridgeProcessMixin {
);
}

Future<aedappfm.Result<({double fee, bool? isChargeable}), aedappfm.Failure>>
getFee() async {
Future<aedappfm.Result<double, aedappfm.Failure>> getFee() async {
return aedappfm.Result.guard(
() async {
try {
Expand All @@ -197,15 +196,9 @@ class EVMHTLCNative with EVMBridgeProcessMixin {

final BigInt fee = feeMap[0];
final etherAmount = EtherAmount.fromBigInt(EtherUnit.wei, fee);
return (
fee: etherAmount.getValueInUnit(EtherUnit.ether),
isChargeable: true,
);
return etherAmount.getValueInUnit(EtherUnit.ether);
} catch (e) {
return (
fee: 0.0,
isChargeable: false,
);
return 0.0;
}
},
);
Expand Down
6 changes: 4 additions & 2 deletions lib/application/contracts/evm_lp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,11 @@ class EVMLP with EVMBridgeProcessMixin {
Swap(
htlcContractAddressEVM: (swaps[0] as EthereumAddress).hex,
htlcContractAddressAE: bytesToHex(swaps[1] as List<int>),
swapProcess: (swaps[2] as BigInt).toInt() == 1
swapProcess: (swaps[2] as BigInt).toInt() == 0
? SwapProcess.chargeable
: SwapProcess.signed,
: (swaps[2] as BigInt).toInt() == 1
? SwapProcess.signed
: null,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class BridgeConfirmSheetState extends ConsumerState<BridgeConfirmSheet> {
const Padding(
padding: EdgeInsets.symmetric(vertical: 10),
child: SizedBox(
height: 45,
child: aedappfm.InfoBanner(
'The UCO amount you entered has been reduced to include Archethic transaction fees.',
aedappfm.InfoBannerType.request,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:aebridge/application/contracts/evm_htlc.dart';
import 'package:aebridge/ui/views/bridge/bloc/state.dart';
import 'package:aebridge/ui/views/refund/layouts/refund_sheet.dart';
import 'package:archethic_dapp_framework_flutter/archethic_dapp_framework_flutter.dart'
Expand All @@ -18,48 +17,40 @@ class LocalHistoryCardOptionsRefund extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final stepOk = bridge.blockchainFrom!.isArchethic ? 3 : 4;

if (bridge.failure == null ||
bridge.htlcEVMAddress == null ||
(bridge.blockchainFrom != null &&
bridge.blockchainFrom!.isArchethic == true)) {
bridge.currentStep < stepOk ||
(bridge.htlcEVMAddress == null && bridge.htlcAEAddress == null) ||
bridge.blockchainFrom == null) {
return const SizedBox.shrink();
}

return FutureBuilder<int>(
future: EVMHTLC(
bridge.blockchainFrom!.providerEndpoint,
bridge.blockchainFrom!.htlcAddress!,
bridge.blockchainFrom!.chainId,
).getStatus(),
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data != 1 && snapshot.data != 2) {
return Padding(
padding: const EdgeInsets.only(left: 10),
child: InkWell(
onTap: () {
final helper = aedappfm.QueryParameterHelper();
final htlcAddressEncoded = helper
.encodeQueryParameter(bridge.blockchainFrom!.htlcAddress!);
context.go(
Uri(
path: RefundSheet.routerPage,
queryParameters: {
'htlcAddress': htlcAddressEncoded,
},
).toString(),
);
return Padding(
padding: const EdgeInsets.only(left: 10),
child: InkWell(
onTap: () {
final helper = aedappfm.QueryParameterHelper();
final htlcAddressEncoded = helper.encodeQueryParameter(
bridge.blockchainFrom!.isArchethic == true
? bridge.htlcAEAddress!
: bridge.htlcEVMAddress!,
);
context.go(
Uri(
path: RefundSheet.routerPage,
queryParameters: {
'htlcAddress': htlcAddressEncoded,
},
child: aedappfm.IconAnimated(
icon: aedappfm.Iconsax.empty_wallet_change,
color: Colors.white,
tooltip:
AppLocalizations.of(context)!.local_history_option_refund,
),
),
).toString(),
);
}
return const SizedBox.shrink();
},
},
child: aedappfm.IconAnimated(
icon: aedappfm.Iconsax.empty_wallet_change,
color: Colors.white,
tooltip: AppLocalizations.of(context)!.local_history_option_refund,
),
),
);
}
}
Loading

0 comments on commit 493ba0f

Please sign in to comment.