commit
00c008ed8b
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 548 B |
@ -0,0 +1,32 @@
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
|
||||
enum PinCodeRequiredDuration {
|
||||
always(0),
|
||||
tenminutes(10),
|
||||
onehour(60);
|
||||
|
||||
const PinCodeRequiredDuration(this.value);
|
||||
final int value;
|
||||
|
||||
static PinCodeRequiredDuration deserialize({required int raw}) =>
|
||||
PinCodeRequiredDuration.values.firstWhere((e) => e.value == raw);
|
||||
|
||||
@override
|
||||
String toString(){
|
||||
String label = '';
|
||||
switch (this) {
|
||||
case PinCodeRequiredDuration.always:
|
||||
label = S.current.always;
|
||||
break;
|
||||
case PinCodeRequiredDuration.tenminutes:
|
||||
label = S.current.minutes_to_pin_code('10');
|
||||
break;
|
||||
case PinCodeRequiredDuration.onehour:
|
||||
label = S.current.minutes_to_pin_code('60');
|
||||
break;
|
||||
}
|
||||
return label;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +1,25 @@
|
||||
class PaymentRequest {
|
||||
PaymentRequest(this.address, this.amount, this.note);
|
||||
PaymentRequest(this.address, this.amount, this.note, this.scheme);
|
||||
|
||||
factory PaymentRequest.fromUri(Uri uri) {
|
||||
factory PaymentRequest.fromUri(Uri? uri) {
|
||||
var address = "";
|
||||
var amount = "";
|
||||
var note = "";
|
||||
var scheme = "";
|
||||
|
||||
if (uri != null) {
|
||||
address = uri.path;
|
||||
amount = uri.queryParameters['tx_amount'] ?? uri.queryParameters['amount'] ?? "";
|
||||
note = uri.queryParameters['tx_description']
|
||||
?? uri.queryParameters['message'] ?? "";
|
||||
scheme = uri.scheme;
|
||||
}
|
||||
|
||||
return PaymentRequest(address, amount, note);
|
||||
return PaymentRequest(address, amount, note, scheme);
|
||||
}
|
||||
|
||||
final String address;
|
||||
final String amount;
|
||||
final String note;
|
||||
final String scheme;
|
||||
}
|
@ -1,29 +1,51 @@
|
||||
import 'package:cake_wallet/core/execution_state.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_gift_card.dart';
|
||||
import 'package:cake_wallet/ionia/ionia_service.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
part 'ionia_custom_redeem_view_model.g.dart';
|
||||
|
||||
class IoniaCustomRedeemViewModel = IoniaCustomRedeemViewModelBase with _$IoniaCustomRedeemViewModel;
|
||||
|
||||
abstract class IoniaCustomRedeemViewModelBase with Store {
|
||||
IoniaCustomRedeemViewModelBase(this.giftCard)
|
||||
: amount = 0;
|
||||
IoniaCustomRedeemViewModelBase({
|
||||
required this.giftCard,
|
||||
required this.ioniaService,
|
||||
}) : amount = 0,
|
||||
redeemState = InitialExecutionState();
|
||||
|
||||
final IoniaGiftCard giftCard;
|
||||
|
||||
final IoniaService ioniaService;
|
||||
|
||||
@observable
|
||||
ExecutionState redeemState;
|
||||
|
||||
@observable
|
||||
double amount;
|
||||
|
||||
@computed
|
||||
double get remaining => amount <= giftCard.remainingAmount ? giftCard.remainingAmount - amount : 0;
|
||||
double get remaining =>
|
||||
amount <= giftCard.remainingAmount ? giftCard.remainingAmount - amount : 0;
|
||||
|
||||
@computed
|
||||
String get formattedRemaining => remaining.toStringAsFixed(2);
|
||||
String get formattedRemaining => remaining.toStringAsFixed(2);
|
||||
|
||||
@computed
|
||||
bool get disableRedeem => amount > giftCard.remainingAmount;
|
||||
|
||||
@action
|
||||
void updateAmount(String text){
|
||||
amount = text.isEmpty ? 0 : (double.parse(text.replaceAll(',', '.')) ?? 0);
|
||||
void updateAmount(String text) {
|
||||
amount = double.tryParse(text.replaceAll(',', '.')) ?? 0;
|
||||
}
|
||||
|
||||
}
|
||||
@action
|
||||
Future<void> addCustomRedeem() async {
|
||||
try {
|
||||
redeemState = IsExecutingState();
|
||||
await ioniaService.redeem(giftCardId: giftCard.id, amount: amount);
|
||||
redeemState = ExecutedSuccessfullyState();
|
||||
} catch (e) {
|
||||
redeemState = FailureState(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue