diff --git a/extension/lib/util.ts b/extension/lib/util.ts index d2055c46c1..5bf16778bd 100644 --- a/extension/lib/util.ts +++ b/extension/lib/util.ts @@ -62,6 +62,13 @@ class Util { }; C.AccountSelect(message.accountId, '', 0, '', (message: any) => { + if (message.error.code) { + if (onError) { + onError(message.error); + }; + return; + }; + S.Auth.accountSet(message.account); S.Common.configSet(message.account.config, false); S.Common.showVaultSet(false); diff --git a/src/json/error.ts b/src/json/error.ts index 3fb9825922..4f6ee4ba86 100644 --- a/src/json/error.ts +++ b/src/json/error.ts @@ -13,6 +13,7 @@ export default { LIMIT_OF_ROWS_OR_RELATIONS_EXCEEDED: 7, FILE_LOAD_ERROR: 8, INSUFFICIENT_PERMISSIONS: 9, + ACCOUNT_STORE_NOT_MIGRATED: 113, Import: { INTERNAL_ERROR: 3, diff --git a/src/scss/page/auth.scss b/src/scss/page/auth.scss index fc7fd6f4c1..16717893b9 100644 --- a/src/scss/page/auth.scss +++ b/src/scss/page/auth.scss @@ -276,3 +276,7 @@ html.bodyAuthDeleted { .button { width: 320px; } .remove { color: var(--color-red) !important; } } + +.pageAuthMigrate { + .frame { width: 480px; } +} \ No newline at end of file diff --git a/src/ts/component/footer/main/object.tsx b/src/ts/component/footer/main/object.tsx index f4ad3ae6d2..2ab87c0871 100644 --- a/src/ts/component/footer/main/object.tsx +++ b/src/ts/component/footer/main/object.tsx @@ -9,9 +9,9 @@ const FooterMainObject = observer(forwardRef<{}, I.FooterComponent>((props, ref) const { onHelp } = props; const { show } = S.Progress; const theme = S.Common.getThemeClass(); - const current = S.Progress.getCurrent(); - const total = S.Progress.getTotal(); - const percent = Math.round((current / total) * 100); + const skipType = [ I.ProgressType.Migrate ]; + const list = S.Progress.getList(it => !skipType.includes(it.type)); + const percent = S.Progress.getPercent(list); const color = J.Theme[theme].progress; const onTooltipShow = (e: any, text: string, caption?: string) => { @@ -23,7 +23,7 @@ const FooterMainObject = observer(forwardRef<{}, I.FooterComponent>((props, ref) return (
- {total ? ( + {percent ? (
((props, ref: any) return; }; + if (code == J.Error.Code.ACCOUNT_STORE_NOT_MIGRATED) { + U.Router.go('/auth/migrate', {}); + return; + }; + setError(text); phraseRef.current?.setError(true); submitRef.current?.setLoading(false); diff --git a/src/ts/component/page/auth/migrate.tsx b/src/ts/component/page/auth/migrate.tsx new file mode 100644 index 0000000000..33840658c2 --- /dev/null +++ b/src/ts/component/page/auth/migrate.tsx @@ -0,0 +1,68 @@ +import React, { forwardRef, useEffect, useState } from 'react'; +import { observer } from 'mobx-react'; +import { Frame, Error, ProgressBar } from 'Component'; +import { I, C, S, U, Animation, Storage } from 'Lib'; + +const PageAuthMigrate = observer(forwardRef<{}, I.PageComponent>((props, ref) => { + + const { dataPath } = S.Common; + const accountId = Storage.get('accountId'); + const spaceId = Storage.get('spaceId'); + const [ error, setError ] = useState(''); + const { networkConfig } = S.Auth; + const { mode, path } = networkConfig; + const types = [ I.ProgressType.Migrate ]; + const list = S.Progress.getList(it => types.includes(it.type)); + const progress = list.length ? list[0] : null; + const segments = []; + + if (progress) { + segments.push({ name: 'migrate', caption: 'Migrate', percent: progress.current / progress.total, isActive: true }); + }; + + useEffect(() => { + S.Auth.clearAll(); + + Animation.to(() => { + C.AccountMigrate(accountId, dataPath, (message: any) => { + if (message.error.code) { + setError(message.error.description); + return; + }; + + C.AccountSelect(accountId, dataPath, mode, path, (message: any) => { + const { account } = message; + + if (!account) { + return; + }; + + S.Auth.accountSet(account); + S.Common.configSet(account.config, false); + + const routeParam = { replace: true }; + + if (spaceId) { + U.Router.switchSpace(spaceId, '', false, routeParam); + } else { + U.Data.onAuthWithoutSpace(routeParam); + }; + + U.Data.onInfo(account.info); + U.Data.onAuthOnce(false); + }); + + }); + }); + }, []); + + return ( + + + + + ); + +})); + +export default PageAuthMigrate; \ No newline at end of file diff --git a/src/ts/component/page/auth/setup.tsx b/src/ts/component/page/auth/setup.tsx index d9f3795b87..800526c320 100644 --- a/src/ts/component/page/auth/setup.tsx +++ b/src/ts/component/page/auth/setup.tsx @@ -85,6 +85,11 @@ const PageAuthSetup = observer(forwardRef<{}, I.PageComponent>((props, ref) => { return false; }; + if (error.code == J.Error.Code.ACCOUNT_STORE_NOT_MIGRATED) { + U.Router.go('/auth/migrate', {}); + return; + }; + setError(error); return U.Common.checkErrorCommon(error.code); }; diff --git a/src/ts/component/page/index.tsx b/src/ts/component/page/index.tsx index 49edce50c0..89ab32ff28 100644 --- a/src/ts/component/page/index.tsx +++ b/src/ts/component/page/index.tsx @@ -11,6 +11,7 @@ import PageAuthPinCheck from './auth/pinCheck'; import PageAuthSetup from './auth/setup'; import PageAuthOnboard from './auth/onboard'; import PageAuthDeleted from './auth/deleted'; +import PageAuthMigrate from './auth/migrate'; import PageMainBlank from './main/blank'; import PageMainEmpty from './main/empty'; @@ -41,6 +42,7 @@ const Components = { 'auth/setup': PageAuthSetup, 'auth/onboard': PageAuthOnboard, 'auth/deleted': PageAuthDeleted, + 'auth/migrate': PageAuthMigrate, 'main/blank': PageMainBlank, 'main/empty': PageMainEmpty, diff --git a/src/ts/component/util/progress.tsx b/src/ts/component/util/progress.tsx index 5b651971c4..58b9759497 100644 --- a/src/ts/component/util/progress.tsx +++ b/src/ts/component/util/progress.tsx @@ -7,8 +7,9 @@ import { I, S, U, C, J, Storage, keyboard, translate } from 'Lib'; const Progress: FC = observer(() => { const { show } = S.Progress; - const list = S.Progress.getList(); - const percent = S.Progress.getPercent(); + const skipType = [ I.ProgressType.Migrate ]; + const list = S.Progress.getList(it => !skipType.includes(it.type)); + const percent = S.Progress.getPercent(list); const nodeRef = useRef(null); const innerRef = useRef(null); const dx = useRef(0); diff --git a/src/ts/lib/api/command.ts b/src/ts/lib/api/command.ts index c2cad4cf22..d62c12c0ef 100644 --- a/src/ts/lib/api/command.ts +++ b/src/ts/lib/api/command.ts @@ -195,6 +195,15 @@ export const AccountSelect = (id: string, path: string, mode: I.NetworkMode, net dispatcher.request(AccountSelect.name, request, callBack); }; +export const AccountMigrate = (id: string, path: string, callBack?: (message: any) => void) => { + const request = new Rpc.Account.Migrate.Request(); + + request.setId(id); + request.setRootpath(path); + + dispatcher.request(AccountMigrate.name, request, callBack); +}; + export const AccountStop = (removeData: boolean, callBack?: (message: any) => void) => { const request = new Rpc.Account.Stop.Request(); diff --git a/src/ts/store/progress.ts b/src/ts/store/progress.ts index 4416ffc197..d71ef7dd93 100644 --- a/src/ts/store/progress.ts +++ b/src/ts/store/progress.ts @@ -49,32 +49,28 @@ class ProgressStore { this.showValue = Boolean(v); }; - getList () { + getList (filter?: (it: I.Progress) => boolean) { const { space } = S.Common; - const skip = [ I.ProgressState.Done, I.ProgressState.Canceled ]; + const skipState = [ I.ProgressState.Done, I.ProgressState.Canceled ]; - return this.list.filter(it => (!it.spaceId || (it.spaceId == space)) && !skip.includes(it.state)); + return this.list.filter(it => { + let ret = true; + + if (filter) { + ret = filter(it); + }; + + return ret && (!it.spaceId || (it.spaceId == space)) && !skipState.includes(it.state); + }); }; getItem (id: string): I.Progress { return this.getList().find(it => it.id == id); }; - getField (field: string): number { - return this.getList().reduce((acc, it) => acc + (Number(it[field]) || 0), 0); - }; - - getCurrent (): number { - return this.getField('current'); - }; - - getTotal (): number { - return this.getField('total'); - }; - - getPercent (): number { - const current = this.getCurrent(); - const total = this.getTotal(); + getPercent (list: I.Progress[]): number { + const current = list.reduce((acc, it) => acc + (Number(it.current) || 0), 0); + const total = list.reduce((acc, it) => acc + (Number(it.total) || 0), 0); return total > 0 ? Math.min(100, Math.ceil(current / total * 100)) : 0; };