Skip to content

Commit

Permalink
install expo review module and adjust mmkv schema to add review tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
walmat committed Oct 13, 2023
1 parent cd2084c commit c331114
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MMKV } from 'react-native-mmkv';

import { Account, Device } from '@/storage/schema';
import { Account, Device, Review } from '@/storage/schema';
import { EthereumAddress } from '@/entities';
import { Network } from '@/networks/types';

Expand Down Expand Up @@ -76,3 +76,5 @@ export const device = new Storage<[], Device>({ id: 'global' });
export const account = new Storage<[EthereumAddress, Network], Account>({
id: 'account',
});

export const review = new Storage<[], Review>({ id: 'review' });
29 changes: 29 additions & 0 deletions src/storage/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,32 @@ export type Legacy = {
export type Account = {
totalTokens: number;
};

export const enum ReviewPromptAction {
SuccessfulFiatToCryptoPurchase = 'SuccessfulFiatToCryptoPurchase',
DappConnections = 'DappConnections',
NumberOfSwaps = 'NumberOfSwaps',
BridgeToL2 = 'BridgeToL2',
AddingContact = 'AddingContact',
EnsNameSearch = 'EnsNameSearch',
EnsNameRegistration = 'EnsNameRegistration',
WatchWallet = 'WatchWallet',
NftFloorPriceVisitThrice = 'NftFloorPriceVisitThrice',
}

export type Action = {
id: ReviewPromptAction;
timeOfLastDispatch: number;
numOfTimesDispatched: number;
};

/**
* Actions that the user can take that we want to track for review purposes
* Each action has a specific number of times they must be performed before prompting for review
*
* NOTE: if a user has already reviewed, we don't want to prompt them again
*/
export type Review = {
hasReviewed: boolean;
actions: Action[];
};
15 changes: 3 additions & 12 deletions src/utils/reviewAlert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@ export const REVIEW_ASKED_KEY = 'AppStoreReviewAsked';
let reviewDisplayedInTheSession = false;
const TWO_MONTHS = 2 * 30 * 24 * 60 * 60 * 1000;

export const enum ReviewPromptAction {
FiatToCryptoPurchase = 'FiatToCryptoPurchase',
DappConnections = 'DappConnections',
NumberOfSwaps = 'NumberOfSwaps',
BridgeToL2 = 'BridgeToL2',
AddingContact = 'AddingContact',
EnsNameSearch = 'EnsNameSearch',
EnsNameRegistration = 'EnsNameRegistration',
WatchWallet = 'WatchWallet',
NftFloorPriceVisitThrice = 'NftFloorPriceVisitThrice',
}
export const shouldPromptForReview = async (shouldPrompt = false) => {
// when a user manually prompts for review on their own
if (shouldPrompt) return true;

export const shouldPromptForReview = async () => {
const reviewAsked = await AsyncStorage.getItem(REVIEW_ASKED_KEY);
if (Number(reviewAsked) > Date.now() - TWO_MONTHS) {
return false;
Expand Down

0 comments on commit c331114

Please sign in to comment.