Skip to content

Commit

Permalink
feat: filter payment methods using dap protocol (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-tbd authored Aug 26, 2024
1 parent 3b8a954 commit acca51c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
36 changes: 20 additions & 16 deletions lib/features/payment/payment_amount_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,31 @@ class PaymentAmountPage extends HookConsumerWidget {
MaterialPageRoute(
builder: (context) {
final paymentDetailsState =
paymentState.paymentDetailsState ??
PaymentDetailsState();
(paymentState.paymentDetailsState ??
PaymentDetailsState())
.copyWith(
paymentCurrency: paymentState.transactionType ==
TransactionType.deposit
? state.value?.payinCurrency
: state.value?.payoutCurrency,
paymentMethods: paymentState.transactionType ==
TransactionType.deposit
? state
.value?.selectedOffering?.data.payin.methods
.map(PaymentMethod.fromPayinMethod)
.toList()
: state
.value?.selectedOffering?.data.payout.methods
.map(PaymentMethod.fromPayoutMethod)
.toList(),
);

return PaymentDetailsPage(
paymentState: paymentState.copyWith(
paymentAmountState: state.value,
paymentDetailsState: paymentDetailsState.copyWith(
paymentCurrency: paymentState.transactionType ==
TransactionType.deposit
? state.value?.payinCurrency
: state.value?.payoutCurrency,
paymentMethods: paymentState.transactionType ==
TransactionType.deposit
? state.value?.selectedOffering?.data.payin
.methods
.map(PaymentMethod.fromPayinMethod)
.toList()
: state.value?.selectedOffering?.data.payout
.methods
.map(PaymentMethod.fromPayoutMethod)
.toList(),
paymentMethods:
paymentDetailsState.filterDapProtocol(),
),
),
);
Expand Down
11 changes: 11 additions & 0 deletions lib/features/payment/payment_details_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ class PaymentDetailsState {
)
.toList();

List<PaymentMethod>? filterDapProtocol() => paymentMethods
?.where(
(method) => method.kind.contains(
PaymentMethod.protocolPaymentMap[
moneyAddresses?.firstOrNull?.css.split(':').firstOrNull ??
''] ??
'',
),
)
.toList();

PaymentDetailsState copyWith({
String? paymentCurrency,
String? paymentName,
Expand Down
5 changes: 5 additions & 0 deletions lib/features/payment/payment_method.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ class PaymentMethod {
fee: fee ?? this.fee,
);
}

static const Map<String, String> protocolPaymentMap = {
'addr': 'BTC_ONCHAIN_PAYOUT',
'lnaddr': 'BTC_LN_PAYOUT',
};
}

0 comments on commit acca51c

Please sign in to comment.