Skip to content

Commit

Permalink
table view for pro version screen
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalkishor1991 committed Jul 7, 2024
1 parent 5d0c9ae commit b293c8e
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 143 deletions.
8 changes: 6 additions & 2 deletions android/fastlane/metadata/android/en-US/full_description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ KEY FEATURES
* Access a color palette library with Material Design, CSS, and Tailwind palettes
* Download palettes as PNG images
* Rearrange colors in a palette with ease
* Explore AI generated color palettes

PRO BENEFITS

Add more than 4 colors to a palette
Basic
* Add more than 4 colors to a palette
Advance
* AI chat to create color palette
* AI color picker

DESCRIPTION

Expand Down
2 changes: 2 additions & 0 deletions constants/Styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default {
darkGrey: '#333',
white: '#fff',
black: '#000',
darkGreen: '#006400',
darkRed: '#8B0000',
backgroundColor: '#f2f2f2',
overlay: 'rgba(0, 0, 0, 0.5)',
primaryDark: '#C94740',
Expand Down
60 changes: 36 additions & 24 deletions libs/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@ const isProduction = () => {
};

const planToSKUMapping = {
basic: "huehive_pro_basic",
advance: "croma_pro"
free: {
basic: "huehive_pro_basic",
advance: "croma_pro"
},
basic: {
advance: "huehive_basic_to_advance"
}
}

const skuToPlanMapping = {
"huehive_pro_basic": "basic",
"croma_pro": "advance",
"huehive_basic_to_advance": "advance"
}

const skuToPlanMapping = Object.fromEntries(
Object.entries(planToSKUMapping).map(([key, value]) => [value, key])
);

const readRemoteConfig = async (key) => {
// Native module always returns string. So, we need to convert it to boolean.
return (await NativeModules.CromaModule.getConfigString(key)) == 'true';
};

const productSku = function () {
//return 'local_test1';
return Platform.OS === 'android' ? 'croma_pro' : 'app_croma';
};
const sendClientError = (event, errorMessage, stacktrace) => {
if (isProduction()) {
sendClientErrorAsync(event + ' - ' + errorMessage, stacktrace || new Error().stack);
Expand All @@ -49,21 +54,19 @@ function isObject(value) {
return value && typeof value === 'object' && value.constructor === Object;
}

const purchase = async function (setPurchase, productSKU) {
if (!productSKU) {
productSKU = productSku();
}
const purchase = async function (setPurchase, currentPlan, toPlan) {
try {
await getProducts({ skus: [productSKU] });
const productSKU = planToSKUMapping[currentPlan][toPlan]
await getProducts({ skus: [productSKU]});
await requestPurchase({
skus: [productSKU]
});
await setPurchase(skuToPlanMapping[productSKU]);
await setPurchase(toPlan);
logEvent('purchase_successful');
notifyMessage('Congrats, You are now a pro user!');
} catch (err) {
if (err.code == 'E_ALREADY_OWNED') {
setPurchase(skuToPlanMapping[productSKU]);
setPurchase(toPlan);
notifyMessage('Purchase restored successfully!');
} else {
console.warn(err.code, err.message);
Expand All @@ -79,17 +82,25 @@ const initPurchase = async function (
retryCount = 3,
retryDelay = 500
) {
const determinePlan = (plans) => {
if (plans.includes('advance')) {
return 'advance';
} else if (plans.includes('basic')) {
return 'basic';
}
return null;
};

const retryPurchase = async (retries) => {
try {
let products = await getAvailablePurchases();

const basicPlan = products.find((product) => product.productId === planToSKUMapping.basic);
const advancePlan = products.find((product) => product.productId === planToSKUMapping.advance);
if (basicPlan || advancePlan) {
const plan = basicPlan ? 'basic': 'advance';
await setPurchase(plan);
const plans = products.map(product => skuToPlanMapping[product.productId]);
const selectedPlan = determinePlan(plans);

if (selectedPlan) {
await setPurchase(selectedPlan);
if (showMessage) {
notifyMessage('Congrats, You are already a pro (' + plan + ') user!');
notifyMessage(`Congrats, You are already a pro (${selectedPlan}) user!`);
}
}
} catch (e) {
Expand All @@ -100,14 +111,15 @@ const initPurchase = async function (
} else {
logEvent('init_purchase_failed', e.message);
notifyMessage('Init purchase failed: ' + e.message);
sendClientError('init_purchase_failed_' + retryCount, e.message, e.stack);
}
sendClientError('init_purchase_failed_' + retryCount, e.message, e.stack);
}
};

await retryPurchase(retryCount);
};


const getAvailablePurchases = async () => {
try {
const purchases = await RNIap.getAvailablePurchases();
Expand Down
Loading

0 comments on commit b293c8e

Please sign in to comment.