Skip to content

Commit

Permalink
fix: clear Monetization state after success payment
Browse files Browse the repository at this point in the history
  • Loading branch information
N3TC4T committed Jan 21, 2025
1 parent 9259641 commit ea1ba78
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
10 changes: 0 additions & 10 deletions src/components/Modules/MonetizationElement/MonetizationElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,12 @@ class MonetizationElement extends PureComponent<Props, State> {
});
};

onSuccessPurchase = () => {
// purchase was successful clear the monetization status
ProfileRepository.saveProfile({
monetization: {
monetizationStatus: MonetizationStatus.NONE,
},
});
};

purchaseProduct = () => {
const { productForPurchase, monetizationType } = this.state;

Navigator.showModal<PurchaseProductModalProps>(AppScreens.Modal.PurchaseProduct, {
productId: productForPurchase!,
productDescription: monetizationType!,
onSuccessPurchase: this.onSuccessPurchase,
});
};

Expand Down
18 changes: 12 additions & 6 deletions src/screens/Modal/PurchaseProduct/PurchaseProductModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import { ComplianceLinks } from '@common/constants/endpoints';
import { Spacer, CountDown, Button, Icon, Footer } from '@components/General';
import { ProductDetailsElement } from '@components/Modules/ProductDetailsElement';

import { ProfileRepository } from '@store/repositories';
import { MonetizationStatus } from '@store/types';

import { Images } from '@common/helpers/images';

import Localize from '@locale';
Expand All @@ -32,7 +35,6 @@ import styles from './styles';
export interface Props {
productId: string;
productDescription: string;
onSuccessPurchase?: () => void;
onClose?: (successPayment: boolean) => void;
}

Expand Down Expand Up @@ -89,12 +91,16 @@ class PurchaseProductModal extends Component<Props, State> {
};

onSuccessPurchase = async () => {
const { onSuccessPurchase } = this.props;

if (typeof onSuccessPurchase === 'function') {
onSuccessPurchase();
}
// purchase was successful clear the monetization status
ProfileRepository.saveProfile({
monetization: {
monetizationStatus: MonetizationStatus.NONE,
productForPurchase: '',
monetizationType: '',
},
});

// set the state
this.setState({
purchaseSuccess: true,
});
Expand Down
6 changes: 5 additions & 1 deletion src/screens/Modal/XAppBrowser/XAppBrowserModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,11 @@ class XAppBrowserModal extends Component<Props, State> {
Navigator.showModal<PurchaseProductModalProps>(AppScreens.Modal.PurchaseProduct, {
productId: monetization.productForPurchase!,
productDescription: monetization.monetizationType!,
onSuccessPurchase: this.lunchApp,
onClose: (successPayment: boolean) => {
if (successPayment) {
this.lunchApp();
}
},
});
};

Expand Down

0 comments on commit ea1ba78

Please sign in to comment.