updateInstrument method

Future<void> updateInstrument({
  1. required Instrument instrument,
  2. required InstrumentRequest instrumentRequest,
})

updates instrument expiry date

Implementation

Future<void> updateInstrument(
    {required Instrument instrument,
    required InstrumentRequest instrumentRequest}) async {
  final customer = state.value!;

  final updatedInstrument = await checkout.updateInstrument(
      instrument: instrument, instrumentRequest: instrumentRequest);

  state = AsyncValue.data(
    customer.copyWith(
      instruments: [
        for (final i in customer.instruments)
          if (i.id == updatedInstrument.id) updatedInstrument else i
      ],
      defaultInstrument:
          updatedInstrument.id == customer.defaultInstrument?.id
              ? updatedInstrument
              : null,
    ),
  );
}