-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui-ux): UI for opt out anonymized data instrumentation (#4177)
* added analytics section in settings page * added ios prompt * added functionality * added DE and FR translations * added alert for first login * fixed typing issue * added missing translations * added localstorage * added e2e test * added chinese translations * added missing chinese translations * only saveTx if isAnalyticsOn is true * fixed lint issue * added boolean for first modal * changed to use local storage * cleaned up local storage * stored first modal in local storage too * revert additional space in main.tsx * update e2e test * added border * pr comments (name change and add timeout) * added 1000ms timeout for first modal * changed timeout to 5 secs * revert back to 1000ms * switched analytics switch to use state variable instead * switched to state variable for condition check
- Loading branch information
Showing
15 changed files
with
408 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import AsyncStorage from "@react-native-async-storage/async-storage"; | ||
|
||
const STORAGE_PREFIX_KEY = "WALLET."; | ||
|
||
export async function getStorageItem<T>(key: string): Promise<T | null> { | ||
if (typeof window === "undefined") { | ||
return null; | ||
} | ||
const prefixedKey = `${STORAGE_PREFIX_KEY}${key}`; | ||
const value = await AsyncStorage.getItem(prefixedKey); | ||
const currentValue = JSON.parse(value || String(null)); | ||
return currentValue === null ? undefined : currentValue; | ||
} | ||
|
||
export async function setStorageItem<T>(key: string, value: T) { | ||
if (typeof window === "undefined") { | ||
return; | ||
} | ||
const prefixedKey = `${STORAGE_PREFIX_KEY}${key}`; | ||
await AsyncStorage.setItem(prefixedKey, JSON.stringify(value)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
mobile-app/app/screens/AppNavigator/screens/Settings/screens/AnalyticsScreen.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { | ||
ThemedScrollViewV2, | ||
ThemedSectionTitleV2, | ||
ThemedTextV2, | ||
ThemedViewV2, | ||
} from "@components/themed"; | ||
import { WalletAlert } from "@components/WalletAlert"; | ||
import { translate } from "@translations"; | ||
import { tailwind } from "@tailwind"; | ||
import { Switch } from "@components"; | ||
import { useAnalytics } from "@shared-contexts/AnalyticsProvider"; | ||
import { useState } from "react"; | ||
|
||
export function AnalyticsScreen(): JSX.Element { | ||
const { isAnalyticsOn, setStorage } = useAnalytics(); | ||
const [isSwitchOn, setIsSwitchOn] = useState<boolean>( | ||
isAnalyticsOn === "true", | ||
); | ||
|
||
return ( | ||
<ThemedScrollViewV2 | ||
style={tailwind("flex-1")} | ||
contentContainerStyle={tailwind("px-5 pb-16")} | ||
testID="analytics_screen" | ||
> | ||
<ThemedSectionTitleV2 | ||
testID="analytics_screen_title" | ||
text={translate("screens/AnalyticsScreen", "ANALYTICS")} | ||
/> | ||
<ThemedViewV2 | ||
style={tailwind( | ||
"flex flex-row items-center justify-between rounded-lg-v2 px-5 py-3", | ||
)} | ||
dark={tailwind("bg-mono-dark-v2-00")} | ||
light={tailwind("bg-mono-light-v2-00")} | ||
> | ||
<ThemedTextV2 | ||
light={tailwind("text-mono-light-v2-900")} | ||
dark={tailwind("text-mono-dark-v2-900")} | ||
style={tailwind("font-normal-v2 text-sm flex-1")} | ||
testID="text_privacy_lock" | ||
> | ||
{translate("screens/AnalyticsScreen", "Allow data access")} | ||
</ThemedTextV2> | ||
<Switch | ||
onValueChange={async () => { | ||
if (isSwitchOn) { | ||
WalletAlert({ | ||
title: translate( | ||
"screens/AnalyticsScreen", | ||
"Are you sure you want to restrict data access?", | ||
), | ||
message: translate( | ||
"screens/AnalyticsScreen", | ||
"Your data is always kept anonymous and is used only for improvements. Are you sure you want to restrict?", | ||
), | ||
buttons: [ | ||
{ | ||
text: translate("screens/AnalyticsScreen", "Cancel"), | ||
style: "cancel", | ||
}, | ||
{ | ||
text: translate("screens/AnalyticsScreen", "Restrict data"), | ||
onPress: async () => { | ||
setStorage("IS_ANALYTICS_ON", "false"); | ||
setIsSwitchOn(false); | ||
}, | ||
style: "destructive", | ||
}, | ||
], | ||
}); | ||
} else { | ||
setStorage("IS_ANALYTICS_ON", "true"); | ||
setIsSwitchOn(true); | ||
} | ||
}} | ||
value={isSwitchOn} | ||
testID="analytics_switch" | ||
/> | ||
</ThemedViewV2> | ||
<ThemedTextV2 | ||
dark={tailwind("text-mono-dark-v2-500")} | ||
light={tailwind("text-mono-light-v2-500")} | ||
style={tailwind("px-5 pt-2 text-xs font-normal-v2")} | ||
> | ||
{translate( | ||
"screens/AnalyticsScreen", | ||
"Participate in BR Analytics to help us make DeFiChain Wallet better.", | ||
)} | ||
</ThemedTextV2> | ||
</ThemedScrollViewV2> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.