|
|
@@ -7,11 +7,12 @@ import Purchases from 'react-native-purchases'
|
|
|
import { useSelector } from "react-redux";
|
|
|
import './product_list.scss'
|
|
|
import { ColorType } from "@/context/themes/color";
|
|
|
-import { payInfo } from "@/services/user";
|
|
|
+import { payInfo, products } from "@/services/user";
|
|
|
import Taro from "@tarojs/taro";
|
|
|
import showAlert from "@/components/basic/Alert";
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
import { AtActivityIndicator } from "taro-ui";
|
|
|
+import NoData from "@/components/view/NoData";
|
|
|
|
|
|
let useNavigation, TouchableOpacity;
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
|
@@ -24,7 +25,9 @@ export default function ProductList() {
|
|
|
const user = useSelector((state: any) => state.user);
|
|
|
// - State for displaying an overlay view
|
|
|
const [isPurchasing, setIsPurchasing] = useState(false);
|
|
|
+ const [showErrorPage, setShowErrorPage] = useState(false);
|
|
|
const [errorCode, setErrorCode] = useState<any>(-1)
|
|
|
+ const [isLoading, setIsLoading] = useState(false)
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
let navigation;
|
|
|
@@ -72,13 +75,46 @@ export default function ProductList() {
|
|
|
// getProducts();
|
|
|
// console.log('aaaa')
|
|
|
// setTimeout(() => {
|
|
|
- getProducts();
|
|
|
+ // getProducts();
|
|
|
+ getSku();
|
|
|
// hi()
|
|
|
// }, 2000)
|
|
|
|
|
|
}
|
|
|
}, [])
|
|
|
|
|
|
+ function getSku() {
|
|
|
+ // Purchases.getOfferings().then(res=>{
|
|
|
+
|
|
|
+ // })
|
|
|
+ setIsLoading(true)
|
|
|
+ Promise.all([Purchases.getOfferings(), products({ store: kIsIOS ? 'app_store' : 'play_store' })]).then(list => {
|
|
|
+
|
|
|
+ var offerings = list[0]
|
|
|
+ var skus: any = (list[1] as any).data
|
|
|
+ if (offerings.current !== null && offerings.current.availablePackages.length !== 0) {
|
|
|
+ var array = (offerings as any).current.availablePackages
|
|
|
+ array.forEach(element => {
|
|
|
+ skus.forEach(sku => {
|
|
|
+ if (element.product.identifier == sku.product_id) {
|
|
|
+ element.product.title = sku.display_name
|
|
|
+ element.product.description = sku.description
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ setPackages(array)
|
|
|
+
|
|
|
+ }
|
|
|
+ setShowErrorPage(false)
|
|
|
+ setIsLoading(false)
|
|
|
+ // console.log(list)
|
|
|
+ }).catch(e => {
|
|
|
+ setShowErrorPage(true)
|
|
|
+ setIsLoading(false)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
async function getProducts() {
|
|
|
console.log('product list get start')
|
|
|
try {
|
|
|
@@ -131,11 +167,16 @@ export default function ProductList() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (packages.length == 0)
|
|
|
+ if (isLoading)
|
|
|
return <View style={{ flex: 1, position: 'relative', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
|
|
<AtActivityIndicator size={40} color="#fff" />
|
|
|
</View>
|
|
|
|
|
|
+ if (showErrorPage)
|
|
|
+ return <View style={{ flex: 1, position: 'relative', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
|
|
+ <NoData refresh={() => { getSku() }} />
|
|
|
+ </View>
|
|
|
+
|
|
|
return <View style={{ flex: 1, position: 'relative' }}>
|
|
|
<View style={{ height: 40 }} />
|
|
|
{
|