Skip to content

Commit

Permalink
Queue updates
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeBellTMH committed Jan 26, 2022
1 parent 33d2f99 commit f2887cb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
19 changes: 17 additions & 2 deletions components/Billing/Billing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { Mutex } from "async-mutex"
import Amplify, { Auth } from "aws-amplify"
import { Body, Card, CardItem, Content, Label } from "native-base"
import onlyLastPromise, { DiscardSignal } from "only-last-promise"
import React, { useState } from "react"
import { ActivityIndicator, Image, Text, TouchableOpacity, View } from "react-native"
import { JCCognitoUser } from "src/types"
Expand All @@ -37,6 +38,18 @@ import "./CardSectionStyles.css"
import EULA from "./eula.json"
import HandleStripePayment from "./HandleStripePayment"

const wrapper = onlyLastPromise()

const wrappedPreviewInvoice = async (invoiceData: any) => {
try {
return await wrapper(Data.previewInvoice(invoiceData))
} catch (error) {
if (!(error instanceof DiscardSignal)) {
throw error
}
}
}

Amplify.configure(awsConfig)
const handleInputMutex = new Mutex()
const CARD_ELEMENT_OPTIONS = {
Expand Down Expand Up @@ -219,7 +232,7 @@ class BillingImpl extends JCComponent<Props, State> {
{
invoiceQueue: [
...this.state.invoiceQueue,
Data.previewInvoice({
wrappedPreviewInvoice({
idempotency: this.state.idempotency,
priceInfo: {
coupon: this.state.coupon,
Expand All @@ -231,7 +244,9 @@ class BillingImpl extends JCComponent<Props, State> {
async () => {
console.log({ invoiceQueue: this.state.invoiceQueue })
try {
const invoice = await this.state.invoiceQueue[this.state.invoiceQueue.length - 1]
const invoice = (await Promise.all(this.state.invoiceQueue))[
this.state.invoiceQueue.length - 1
]
console.log({ invoice1: invoice })
console.log({ invoice: invoice.data.previewInvoice?.invoice })
this.setState({ invoice: invoice.data.previewInvoice?.invoice })
Expand Down
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"moment": "^2.27.0",
"moment-timezone": "^0.5.31",
"native-base": "^2.11.0",
"only-last-promise": "^1.0.0",
"react": "16.13.1",
"react-chips": "^0.8.0",
"react-datepicker": "^3.6.0",
Expand Down
9 changes: 5 additions & 4 deletions src/aws-amplify-react-native.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
declare module 'aws-amplify-react-native';
declare module '@zoomus/websdk';
declare module "aws-amplify-react-native"
declare module "@zoomus/websdk"
declare interface String {
replaceAll(find: any, replace: any): any;
replaceAll(find: any, replace: any): any
}
declare module 'react-chips';
declare module "react-chips"
declare module "only-last-promise"
2 changes: 1 addition & 1 deletion src/overrides-mui.d.ts:
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ type overridesNameToClassKey = {

declare module '@material-ui/core/styles/overrides' {
export interface ComponentNameToClassKey extends overridesNameToClassKey {}
}
};

0 comments on commit f2887cb

Please sign in to comment.