-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
262 additions
and
219 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
51 changes: 51 additions & 0 deletions
51
features/notifications/hooks/use-notifications-permission.ts
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,51 @@ | ||
import { Platform, Linking } from "react-native"; | ||
import { useAppStore } from "@/data/store/appStore"; | ||
import { requestPushNotificationsPermissions } from "../utils/requestPushNotificationsPermissions"; | ||
import { useSettingsStore } from "@/data/store/accountsStore"; | ||
|
||
type UseNotificationsPermissionReturn = { | ||
notificationsPermissionStatus: "granted" | "undetermined" | "denied"; | ||
requestPermission: () => Promise<void>; | ||
setNotificationsSettings: (settings: { | ||
showNotificationScreen: boolean; | ||
}) => void; | ||
}; | ||
|
||
export function useNotificationsPermission(): UseNotificationsPermissionReturn { | ||
const notificationsPermissionStatus = useAppStore( | ||
(s) => s.notificationsPermissionStatus | ||
); | ||
const setNotificationsPermissionStatus = useAppStore( | ||
(s) => s.setNotificationsPermissionStatus | ||
); | ||
const setNotificationsSettings = useSettingsStore( | ||
(s) => s.setNotificationsSettings | ||
); | ||
|
||
const requestPermission = async () => { | ||
if (notificationsPermissionStatus === "denied") { | ||
if (Platform.OS === "android") { | ||
// Android 13 is always denied first so let's try to show | ||
const newStatus = await requestPushNotificationsPermissions(); | ||
if (newStatus === "denied") { | ||
Linking.openSettings(); | ||
} else if (newStatus) { | ||
setNotificationsPermissionStatus(newStatus); | ||
} | ||
} else { | ||
Linking.openSettings(); | ||
} | ||
} else if (notificationsPermissionStatus === "undetermined") { | ||
// Open popup | ||
const newStatus = await requestPushNotificationsPermissions(); | ||
if (!newStatus) return; | ||
setNotificationsPermissionStatus(newStatus); | ||
} | ||
}; | ||
|
||
return { | ||
notificationsPermissionStatus, | ||
requestPermission, | ||
setNotificationsSettings, | ||
}; | ||
} |
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,91 @@ | ||
import React from "react"; | ||
import { Alert, ViewStyle } from "react-native"; | ||
import { VStack } from "@/design-system/VStack"; | ||
import { HStack } from "@/design-system/HStack"; | ||
import { Text } from "@/design-system/Text"; | ||
import { Chip } from "@/design-system/chip"; | ||
import { ThemedStyle, useAppTheme } from "@/theme/useAppTheme"; | ||
import { translate } from "@/i18n"; | ||
import Clipboard from "@react-native-clipboard/clipboard"; | ||
|
||
type ISocialName = { | ||
name: string; | ||
domain?: string; | ||
}; | ||
|
||
type ISocialNamesProps = { | ||
socials?: { | ||
userNames?: ISocialName[]; | ||
ensNames?: ISocialName[]; | ||
unstoppableDomains?: ISocialName[]; | ||
}; | ||
}; | ||
|
||
export function SocialNames({ socials }: ISocialNamesProps) { | ||
const { theme, themed } = useAppTheme(); | ||
|
||
if ( | ||
!socials || | ||
((socials.userNames?.length ?? 0) === 0 && | ||
(socials.ensNames?.length ?? 0) === 0 && | ||
(socials.unstoppableDomains?.length ?? 0) === 0) | ||
) { | ||
return null; | ||
} | ||
|
||
const handleNamePress = (name: string) => { | ||
Clipboard.setString(name); | ||
Alert.alert(translate("profile.copied")); | ||
}; | ||
|
||
const renderSocialChips = ( | ||
items: ISocialName[], | ||
getValue: (item: ISocialName) => string | ||
) => { | ||
return items?.map((item) => ( | ||
<Chip | ||
isActive | ||
key={getValue(item)} | ||
text={getValue(item)} | ||
style={themed($chip)} | ||
onPress={() => handleNamePress(getValue(item))} | ||
/> | ||
)); | ||
}; | ||
|
||
return ( | ||
<VStack style={[themed($section), { paddingTop: theme.spacing.md }]}> | ||
<Text>{translate("profile.names")}</Text> | ||
<HStack style={themed($chipContainer)}> | ||
{renderSocialChips(socials.userNames ?? [], (item) => item.name)} | ||
{renderSocialChips(socials.ensNames ?? [], (item) => item.name)} | ||
{renderSocialChips( | ||
(socials.unstoppableDomains ?? []).filter( | ||
(d) => d.domain && !d.domain.toLowerCase().endsWith(".eth") | ||
), | ||
(item) => item.domain! | ||
)} | ||
</HStack> | ||
</VStack> | ||
); | ||
} | ||
|
||
const $section: ThemedStyle<ViewStyle> = ({ spacing, colors }) => ({ | ||
backgroundColor: colors.background.surface, | ||
borderBottomWidth: spacing.xxs, | ||
borderBottomColor: colors.background.sunken, | ||
paddingHorizontal: spacing.lg, | ||
paddingVertical: spacing.xs, | ||
}); | ||
|
||
const $chipContainer: ThemedStyle<ViewStyle> = ({ spacing }) => ({ | ||
flexWrap: "wrap", | ||
gap: spacing.xs, | ||
paddingVertical: spacing.sm, | ||
}); | ||
|
||
const $chip: ThemedStyle<ViewStyle> = ({ colors, borderRadius }) => ({ | ||
backgroundColor: colors.background.surface, | ||
borderColor: colors.border.subtle, | ||
borderRadius: borderRadius.xs, | ||
}); |
39 changes: 39 additions & 0 deletions
39
features/profiles/utils/__tests__/format-converse-username.test.ts
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,39 @@ | ||
import { getConfig } from "@/config"; | ||
import { formatConverseUsername } from "../format-converse-username"; | ||
|
||
describe("formatConverseUsername", () => { | ||
it("should return undefined when no username provided", () => { | ||
const result = formatConverseUsername(undefined); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it("should format .conversedev.eth/.converse.xyz username and mark as Converse username", () => { | ||
const result = formatConverseUsername( | ||
`louisdev${getConfig().usernameSuffix}` | ||
); | ||
expect(result).toEqual({ | ||
isConverseUsername: true, | ||
username: "@louisdev", | ||
}); | ||
}); | ||
|
||
it("should return non-Converse usernames as-is with appropriate flag", () => { | ||
expect(formatConverseUsername("louisdev.eth")).toEqual({ | ||
isConverseUsername: false, | ||
username: "louisdev.eth", | ||
}); | ||
expect(formatConverseUsername("louisdev")).toEqual({ | ||
isConverseUsername: false, | ||
username: "louisdev", | ||
}); | ||
expect(formatConverseUsername("@louisdev")).toEqual({ | ||
isConverseUsername: false, | ||
username: "@louisdev", | ||
}); | ||
}); | ||
|
||
it("should return undefined for empty string", () => { | ||
const result = formatConverseUsername(""); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
import { getConfig } from "@/config"; | ||
|
||
type IUsernameResult = { | ||
isConverseUsername: boolean; | ||
username: string; | ||
}; | ||
|
||
/** | ||
* Formats usernames from Converse domains by extracting the username part and adding @ prefix | ||
* Returns a result object containing whether it's a Converse username and the formatted/raw username | ||
* @param username - The username to format | ||
* @returns Object containing isConverseUsername flag and formatted/raw username | ||
*/ | ||
export function formatConverseUsername( | ||
username: string | undefined | ||
): IUsernameResult | undefined { | ||
if (!username) return undefined; | ||
|
||
// Check if it's a Converse username (either domain) | ||
if (username.endsWith(getConfig().usernameSuffix)) { | ||
// Extract everything before the domain | ||
const cleanUsername = username.replace(getConfig().usernameSuffix, ""); | ||
return { | ||
isConverseUsername: true, | ||
username: `@${cleanUsername}`, | ||
}; | ||
} | ||
|
||
// Return the raw username for non-Converse usernames | ||
return { | ||
isConverseUsername: false, | ||
username: username, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.