Skip to content

Commit

Permalink
Add Duplicate account name warning when update version
Browse files Browse the repository at this point in the history
  • Loading branch information
Quangdm-cdm committed Jan 10, 2025
1 parent e0f577a commit 786ba8c
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 19 deletions.
66 changes: 66 additions & 0 deletions src/components/Modal/RemindDuplicateAccountNameModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React, { useCallback } from 'react';
import { Button, PageIcon, SwModal, Typography } from 'components/design-system-ui';
import { Linking, View } from 'react-native';
import { useSubWalletTheme } from 'hooks/useSubWalletTheme';
import { Warning } from 'phosphor-react-native';
import { FontMedium } from 'styles/sharedStyles';
import { BACKUP_SEED_PHRASE_CODE_URL } from 'constants/index';
import i18n from 'utils/i18n/i18n';
import { UPGRADE_DUPLICATE_ACCOUNT_NAME } from '@subwallet/extension-base/constants';
import { noop } from 'utils/function';
import { setValueLocalStorageWS } from 'messaging/database';
interface Props {
modalVisible: boolean;
setVisible: (value: boolean) => void;
}

export const RemindDuplicateAccountNameModal = ({ modalVisible, setVisible }: Props) => {
const theme = useSubWalletTheme().swThemes;

const onCancel = useCallback(() => {
setVisible(false);
setValueLocalStorageWS({ key: UPGRADE_DUPLICATE_ACCOUNT_NAME, value: 'false' }).catch(noop);
}, [setVisible]);

return (
<SwModal
isUseModalV2
modalVisible={modalVisible}
setVisible={setVisible}
disabledOnPressBackDrop={true}
isAllowSwipeDown={false}
titleTextAlign={'center'}
hideWhenCloseApp={false}
modalTitle={'Duplicate account name'}>
<View style={{ position: 'relative' }}>
<View style={{ alignItems: 'center' }}>
<PageIcon icon={Warning} color={theme['colorWarning-5']} />

<Typography.Text
style={{
fontSize: theme.fontSizeHeading6,
lineHeight: theme.fontSizeHeading6 * theme.lineHeightHeading6,
color: theme.colorTextLight4,
textAlign: 'center',
...FontMedium,
marginTop: theme.paddingMD,
}}>
<Typography.Text>
{
'You have accounts with the same name. We have added characters to these account names to differentiate them. You can change account names later using '
}
</Typography.Text>
<Typography.Text
onPress={() => Linking.openURL(BACKUP_SEED_PHRASE_CODE_URL)}
style={{ color: theme.colorLink, textDecorationLine: 'underline' }}>
{'this guide'}
</Typography.Text>
</Typography.Text>
</View>
<Button style={{ marginTop: theme.margin }} onPress={onCancel}>
{i18n.buttonTitles.iUnderstand}
</Button>
</View>
</SwModal>
);
};
18 changes: 11 additions & 7 deletions src/components/common/Modal/ConfirmModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface Props {
cancelBtnTitle?: string;
disabledOnPressBackDrop?: boolean;
isAllowSwipeDown?: boolean;
isShowCancelButton?: boolean;
}

const ConfirmModal: React.FC<Props> = ({
Expand All @@ -34,6 +35,7 @@ const ConfirmModal: React.FC<Props> = ({
cancelBtnTitle,
isAllowSwipeDown,
disabledOnPressBackDrop,
isShowCancelButton = true,
}: Props) => {
const theme = useSubWalletTheme().swThemes;
const styles = useMemo(() => createStyle(theme), [theme]);
Expand All @@ -50,13 +52,15 @@ const ConfirmModal: React.FC<Props> = ({
footer={
<>
<View style={styles.footerModalStyle}>
<Button
type="secondary"
style={{ flex: 1, marginRight: 12 }}
onPress={onCancelModal}
icon={<Icon phosphorIcon={XCircle} size={'lg'} weight={'fill'} />}>
{cancelBtnTitle || i18n.common.cancel}
</Button>
{!!isShowCancelButton && (
<Button
type="secondary"
style={{ flex: 1, marginRight: 12 }}
onPress={onCancelModal}
icon={<Icon phosphorIcon={XCircle} size={'lg'} weight={'fill'} />}>
{cancelBtnTitle || i18n.common.cancel}
</Button>
)}
<Button
externalTextStyle={{ flexShrink: 1 }}
style={{ flex: 1 }}
Expand Down
26 changes: 26 additions & 0 deletions src/messaging/database/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { sendMessage } from '..';
import { StorageDataInterface } from '@subwallet/extension-base/types';

export async function exportIndexedDB(): Promise<string> {
return sendMessage('pri(database.export)', null);
}

export async function importIndexedDB(request: string): Promise<boolean> {
return sendMessage('pri(database.import)', request);
}

export async function getIndexedDBJson(): Promise<object> {
return sendMessage('pri(database.exportJson)', null);
}

export async function migrateLocalStorage(request: string): Promise<boolean> {
return sendMessage('pri(database.migrateLocalStorage)', request);
}

export async function setValueLocalStorageWS(request: StorageDataInterface): Promise<boolean> {
return sendMessage('pri(database.setLocalStorage)', request);
}

export async function getValueLocalStorageWS(request: string): Promise<string | null> {
return sendMessage('pri(database.getLocalStorage)', request);
}
1 change: 1 addition & 0 deletions src/messaging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ export * from './manta-pay';
export * from './domain';
export * from './metadata';
export * from './campaigns';
export * from './database';
2 changes: 2 additions & 0 deletions src/providers/AppModalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type ConfirmModalInfo = {
onCompleteModal?: () => void | undefined;
disabledOnPressBackDrop?: boolean;
isAllowSwipeDown?: boolean;
isShowCancelButton?: boolean;
};

export type AddressQrModalInfo = {
Expand Down Expand Up @@ -144,6 +145,7 @@ export const AppModalContextProvider = ({ children }: AppModalContextProviderPro
cancelBtnTitle={confirmModal.cancelBtnTitle}
isAllowSwipeDown={confirmModal.isAllowSwipeDown}
disabledOnPressBackDrop={confirmModal.disabledOnPressBackDrop}
isShowCancelButton={confirmModal.isShowCancelButton}
/>

{addressQrModalState.visible && (
Expand Down
1 change: 1 addition & 0 deletions src/screens/Account/RestoreJson/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export const RestoreJson = () => {
onCancelModal: confirmModal.hideConfirmModal,
completeBtnTitle: 'I understand',
cancelBtnTitle: 'Cancel',
isShowCancelButton: false,
});
},
[confirmModal, onImportFinal, theme.colorPrimary, theme.colorWarning],
Expand Down
42 changes: 30 additions & 12 deletions src/screens/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ import { mmkvStore } from 'utils/storage';
import { GeneralTermModal } from 'components/Modal/GeneralTermModal';
import { TermAndCondition } from 'constants/termAndCondition';
import { RemindBackupModal } from 'components/Modal/RemindBackupModal';
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
import { ALL_ACCOUNT_KEY, UPGRADE_DUPLICATE_ACCOUNT_NAME } from '@subwallet/extension-base/constants';
import { useIsFocused } from '@react-navigation/native';
import { updateMktCampaignStatus } from 'stores/AppState';
import { MissionPoolsByTabview } from 'screens/Home/Browser/MissionPool';
import { computeStatus } from 'utils/missionPools';
import { MissionPoolType } from 'screens/Home/Browser/MissionPool/predefined';
import withPageWrapper from 'components/pageWrapper';
import { NoticeModal } from 'components/Modal/NoticeModal';
import { RemindDuplicateAccountNameModal } from 'components/Modal/RemindDuplicateAccountNameModal';
import { getValueLocalStorageWS } from 'messaging/database';
import { noop } from 'utils/function';

interface tabbarIconColor {
color: string;
Expand Down Expand Up @@ -274,6 +277,7 @@ export const Home = ({ navigation }: Props) => {
const lastTimeLogin = mmkvStore.getNumber('lastTimeLogin');
const [modalVisible, setModalVisible] = useState<boolean>(false);
const [noticeModalVisible, setNoticeModalVisible] = useState<boolean>(false);
const [duplicateModalVisible, setDuplicateModalVisible] = useState<boolean>(false);
const isOpenedNoticeModal = mmkvStore.getBoolean('isOpenedNoticeModal');
const isFocused = useIsFocused();
const dispatch = useDispatch();
Expand Down Expand Up @@ -318,16 +322,26 @@ export const Home = ({ navigation }: Props) => {

useEffect(() => {
const isNeedShowNoticeModal = Platform.OS === 'ios' && parseFloat(Platform.Version) < 16.4;
if (!isLocked && lastTimeLogin && storedRemindBackupTimeout) {
if (Date.now() - lastTimeLogin > storedRemindBackupTimeout) {
setModalVisible(true);
dispatch(updateMktCampaignStatus(false));
} else if (isNeedShowNoticeModal) {
setNoticeModalVisible(true);
dispatch(updateMktCampaignStatus(false));
} else {
dispatch(updateMktCampaignStatus(true));
}
if (!isLocked) {
getValueLocalStorageWS(UPGRADE_DUPLICATE_ACCOUNT_NAME)
.then(value => {
if (value === 'true') {
setDuplicateModalVisible(true);
} else {
if (lastTimeLogin && storedRemindBackupTimeout) {
if (Date.now() - lastTimeLogin > storedRemindBackupTimeout) {
setModalVisible(true);
dispatch(updateMktCampaignStatus(false));
} else if (isNeedShowNoticeModal) {
setNoticeModalVisible(true);
dispatch(updateMktCampaignStatus(false));
} else {
dispatch(updateMktCampaignStatus(true));
}
}
}
})
.catch(noop);
}
}, [dispatch, isLocked, lastTimeLogin, storedRemindBackupTimeout]);

Expand Down Expand Up @@ -357,12 +371,16 @@ export const Home = ({ navigation }: Props) => {
disabledOnPressBackDrop={true}
/>
)}
{!isEmptyAccounts && !needMigrate && isFocused && (
<RemindDuplicateAccountNameModal modalVisible={duplicateModalVisible} setVisible={setDuplicateModalVisible} />
)}

{!isEmptyAccounts && !needMigrate && isFocused && (
<RemindBackupModal modalVisible={modalVisible} setVisible={setModalVisible} />
)}

{!isEmptyAccounts && !isOpenedNoticeModal && !needMigrate && isFocused && !isShowRemindBackupModal.current && (
<NoticeModal modalVisible={noticeModalVisible} setVisible={setNoticeModalVisible} />
<NoticeModal modalVisible={noticeModalVisible} setVisible={setNoticeModalVisible} /> // Consider deleting this modal
)}
</>
);
Expand Down

0 comments on commit 786ba8c

Please sign in to comment.