fetchfundingSources method

void fetchfundingSources(
  1. BuildContext context
)

Implementation

void fetchfundingSources(BuildContext context) async {
  try {
    isLoading(true);
    var request = {
      'token': Storage.getValue(Constants.token),
      'api_key': Constants.apiKey,
      'sub_client_api_key': Storage.getValue(Constants.subClientApiKey)
    };
    var response = await DioClient().request(
        context: context,
        api: '/get-funding-sources',
        method: Method.POST,
        params: request);
    if (response != null) {
      GetFundingResponse getFundingResponse =
          GetFundingResponse.fromJson(response);
      if (getFundingResponse.status == Strings.success) {
        allCards = getFundingResponse.data!.cards!.obs;
        allBankAccounts = getFundingResponse.data!.bankAccounts!.obs;
        isError(false);
      } else {
        isError(true);
        errorMessage.value = response['message'].toString().toTitleCase();
        if (errorMessage.value == 'Token Not Valid') {
          Utils.navigationReplace(context, const Login());
          return Utils.showSnackbar(context, Strings.error,
              'Token has expired please login again!.', AppColors.red);
        }
        return Utils.showSnackbar(
            context, Strings.error, response['message'], AppColors.red);
      }
    }
  } finally {
    isLoading(false);
  }
  update();
}