Skip to content

Commit

Permalink
BTCPay: improve feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dariyoo99 committed May 24, 2024
1 parent 31ef0c5 commit 8278066
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
13 changes: 7 additions & 6 deletions lib/business/btcpay_voucher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ class BtcPayVoucher {
} on TimeoutException {
return BtcPayVoucherRedeemResult.voucherInvalid;
}

switch (response.statusCode) {
case 200:
{
Expand All @@ -149,9 +148,9 @@ class BtcPayVoucher {
case 400 || 422:
{
final json = jsonDecode(response.body);
errorMessage = json[0]['message'] ?? "";
errorMessage = errorMessage.toLowerCase();
if (errorMessage.contains("onchain")) {
errorMessage = json['message'] ?? "";
String errorCode = json['code'] ?? "";
if (errorCode == "payment-method-not-supported") {
errorType = BtcPayVoucherErrorType.onChain;
}

Expand All @@ -171,9 +170,11 @@ class BtcPayVoucher {
}
}

void addPendingTx(String pullPaymentId, String address, Account account) {
void addPendingTx(
String pullPaymentId, String address, Account account, int? amountSats) {
EnvoyStorage().addPendingTx(pullPaymentId, account.id ?? "", DateTime.now(),
TransactionType.btcPay, 0, 0, address);
TransactionType.btcPay, amountSats ?? 0, 0, address,
pullPaymentId: pullPaymentId);
EnvoyStorage().addTxNote(note: "BTCPay voucher", key: address); // TODO: FIGMA
}

Expand Down
8 changes: 5 additions & 3 deletions lib/ui/home/cards/accounts/btcPay/btcpay_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ class BtcPayInfo extends StatelessWidget {
),
if (voucher.amountSats != null)
EnvoyAmount(
amountSats: voucher.amountSats!,
amountWidgetStyle: AmountWidgetStyle.normal,
account: account),
amountSats: voucher.amountSats!,
amountWidgetStyle: AmountWidgetStyle.normal,
account: account,
alignToEnd: false,
),
if (voucher.amountSats ==
null) // TODO: what if amount is in strange currency
Text("${voucher.amount!} ${voucher.currency!}",
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/home/cards/accounts/btcPay/btcpay_loading_payout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class BtcPayLoadingPayoutState extends State<BtcPayLoadingPayout> {

if (result == BtcPayVoucherRedeemResult.success) {
{
addPendingTx(widget.voucher.id, address, widget.account);
addPendingTx(widget.voucher.id, address, widget.account,
widget.voucher.amountSats);
widget.controller.jumpToPage(4);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ class _TransactionsDetailsWidgetState
trailing: Text(getTransactionStatusString(tx),
style: trailingTextStyle),
),
if (tx.pullPaymentId != null)
EnvoyInfoCardListItem(
title: S().coindetails_overlay_paymentID,
icon: const EnvoyIcon(EnvoyIcons.btcPay,
color: EnvoyColors.textPrimary, size: EnvoyIconSize.small),
trailing: Text(tx.pullPaymentId!, style: trailingTextStyle),
),
if (tx.type == TransactionType.ramp)
EnvoyInfoCardListItem(
title: S().coindetails_overlay_rampID,
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/state/transactions_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ Future prunePendingTransactions(
kPrint("Pruning BtcPay tx: ${actualBtcPayTx.txId}");
EnvoyStorage().addTxNote(
note: "BTCPay voucher", key: actualBtcPayTx.txId); // TODO: FIGMA
EnvoyStorage().deleteTxNote(pendingTx.address!);
EnvoyStorage().deletePendingTx(pendingTx.address!);
actualBtcPayTx.setPullPaymentId(pendingTx.pullPaymentId);
EnvoyStorage().deleteTxNote(pendingTx.address!);
EnvoyStorage().deletePendingTx(pendingTx.txId);
});
}
for (var pendingTx in ramp) {
Expand Down
16 changes: 13 additions & 3 deletions lib/util/envoy_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,17 @@ class EnvoyStorage {
.then((event) => event.isNotEmpty);
}

Future addPendingTx(String key, String accountId, DateTime timestamp,
wallet.TransactionType type, int amount, int fee, String address,
{String? purchaseViewToken}) async {
Future addPendingTx(
String key,
String accountId,
DateTime timestamp,
wallet.TransactionType type,
int amount,
int fee,
String address, {
String? purchaseViewToken,
String? pullPaymentId,
}) async {
await pendingTxStore.record(key).put(_db, {
'account': accountId,
'timestamp': timestamp.millisecondsSinceEpoch,
Expand All @@ -270,6 +278,7 @@ class EnvoyStorage {
'fee': fee,
'address': address,
'purchaseViewToken': purchaseViewToken,
'pullPaymentId': pullPaymentId,
});
return true;
}
Expand Down Expand Up @@ -314,6 +323,7 @@ class EnvoyStorage {
e["address"] as String,
type: type,
purchaseViewToken: e['purchaseViewToken'] as String?,
pullPaymentId: e['pullPaymentId'] as String?,
);
},
).toList();
Expand Down

0 comments on commit 8278066

Please sign in to comment.