createOperationDeposit method
- required OperationDepositMethodId methodId,
- required Price nominal,
- OperationDepositSecret? paypal,
- required CountryCode country,
override
Creates a new OperationDeposit.
Implementation
@override
Future<Rx<Operation>?> createOperationDeposit({
required OperationDepositMethodId methodId,
required Price nominal,
OperationDepositSecret? paypal,
required CountryCode country,
}) async {
Log.debug(
'createOperationDeposit(methodId: $methodId, nominal: $nominal, paypal: ${paypal?.obscured}, country: $country)',
'$runtimeType',
);
if (paypal == null) {
throw Exception('`paypal` shouldn\'t be `null`');
}
final mixin = await _graphQlProvider.createOperationDeposit(
methodId: methodId,
kind: OperationDepositInput(
paypal: OperationDepositPayPalInput(
nominal: nominal.sum,
secret: paypal,
),
),
country: country,
);
final OperationsEventsEvent events = OperationsEventsEvent(
OperationsEventsVersioned(
mixin.events.map(operationEvent).toList(),
mixin.ver,
mixin.listVer,
),
);
await _operationsEvent(events, updateVersion: false);
// Await for `transform` callback in [operations] to happen.
await Future.delayed(Duration.zero);
final Operation? operation = events.event.events
.firstWhereOrNull((e) => e.operation.value is OperationDeposit)
?.operation
.value;
if (operation is OperationDeposit) {
final Rx<Operation>? existing = operations.items[operation.id];
if (existing == null) {
Log.debug(
'createOperationDeposit() -> existing(`${operation.id}`) is `null`, thus creating new `Rx`',
'$runtimeType',
);
operations.items[operation.id] = Rx(operation);
}
return existing ?? operations.items[operation.id];
}
return null;
}