Skip to content

Commit

Permalink
fix: Create wallet crash (#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteZhang1024 authored Aug 2, 2022
1 parent 99be41a commit 590c2ba
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,31 @@ class HomePageManager : ViewGroupManager<HomePageView>() {
override fun removeViewAt(parent: HomePageView?, index: Int) {
if (parent == null) return
if (index == 0) {
parent.setHeaderView(View(parent.context), 0)
parent.removeHeaderView()
} else if (index <= mTabs.size) {
mFragments.removeAt(index - 1)
if (index == mTabs.size) {
parent.setViewPager(
(getReactContext(parent).currentActivity as FragmentActivity),
mFragments,
mTabs
)
}
}

override fun removeView(parent: HomePageView?, view: View?) {
if (parent == null) return
if (view == null) return
if (parent.getHeaderView() == view) {
parent.removeHeaderView()
} else {
val index = mFragments.indexOfFirst { it.childView == view }
if (index != -1) {
mFragments.removeAt(index)
}
}
}

override fun removeAllViews(parent: HomePageView?) {
if (parent == null) return
parent.removeHeaderView()
mFragments.clear()
}

override fun needsCustomLayoutForChildren(): Boolean {
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ open class HomePageLayout @JvmOverloads constructor(
return content.findViewById<ViewGroup>(R.id.toolbar)?.getChildAt(0)
}

fun removeHeaderView() {
content.findViewById<ViewGroup>(R.id.toolbar)?.removeAllViews()
}

fun setHeaderView(view: View, height: Int) {
val contentView = content.findViewById<CollapsingToolbarLayout>(R.id.toolbar)
contentView.removeAllViews()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const Done: FC<DoneProps> = ({
}) => {
const intl = useIntl();
const toast = useToast();
const { closeDrawer, resetToRoot } = useNavigationActions();
const { closeDrawer, openRootHome } = useNavigationActions();
useEffect(() => {
async function main() {
try {
Expand All @@ -62,7 +62,7 @@ const Done: FC<DoneProps> = ({
});
}
closeDrawer();
resetToRoot();
openRootHome();
closeExtensionWindowIfOnboardingFinished();
}
main();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const AddImportedOrWatchingAccount = () => {
const intl = useIntl();
const toast = useToast();

const { closeDrawer, resetToRoot } = useNavigationActions();
const { closeDrawer, openRootHome } = useNavigationActions();
const navigation = useNavigation<NavigationProps['navigation']>();

const { control, handleSubmit, getValues, watch } =
Expand Down Expand Up @@ -127,7 +127,7 @@ const AddImportedOrWatchingAccount = () => {
name,
);
closeDrawer();
resetToRoot();
openRootHome();
closeExtensionWindowIfOnboardingFinished();
} catch (e) {
const errorKey = (e as { key: LocaleIds }).key;
Expand All @@ -143,7 +143,7 @@ const AddImportedOrWatchingAccount = () => {
possibleAddTypes,
defaultAccountNames,
closeDrawer,
resetToRoot,
openRootHome,
toast,
intl,
],
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/views/CreateWallet/AddExistingWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const AddExistingWallet = () => {
const intl = useIntl();
const toast = useToast();

const { closeDrawer, resetToRoot } = useNavigationActions();
const { closeDrawer, openRootHome } = useNavigationActions();
const navigation = useNavigation<NavigationProps['navigation']>();

const isSmallScreen = useIsVerticalLayout();
Expand Down Expand Up @@ -153,7 +153,7 @@ const AddExistingWallet = () => {
accountName,
);
closeDrawer();
resetToRoot();
openRootHome();
closeExtensionWindowIfOnboardingFinished();
} catch (e) {
const errorKey = (e as { key: LocaleIds }).key;
Expand All @@ -178,7 +178,7 @@ const AddExistingWallet = () => {
activeNetworkId,
closeDrawer,
intl,
resetToRoot,
openRootHome,
toast,
wallets,
],
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/views/CreateWallet/AppWallet/Mnemonic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const MnemonicContainer = () => {
const { mnemonic, password, withEnableAuthentication } = route.params ?? {};
const toast = useToast();
const intl = useIntl();
const { closeDrawer, resetToRoot } = useNavigationActions();
const { closeDrawer, openRootHome } = useNavigationActions();
const onPromise = useCallback(async () => {
try {
await backgroundApiProxy.serviceAccount.createHDWallet({
Expand All @@ -175,7 +175,7 @@ const MnemonicContainer = () => {
}
closeDrawer();
await wait(600);
resetToRoot();
openRootHome();
await wait(600);
closeExtensionWindowIfOnboardingFinished();
}, [
Expand All @@ -185,7 +185,7 @@ const MnemonicContainer = () => {
closeDrawer,
intl,
toast,
resetToRoot,
openRootHome,
]);
return <Mnemonic mnemonic={mnemonic} onPromise={onPromise} />;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type RouteProps = RouteProp<
const SetupSuccessModal: FC = () => {
const intl = useIntl();
const route = useRoute<RouteProps>();
const { resetToRoot } = useNavigationActions();
const { openRootHome } = useNavigationActions();
// const isSmallScreen = useIsVerticalLayout();

const { device } = route?.params;
Expand Down Expand Up @@ -56,7 +56,7 @@ const SetupSuccessModal: FC = () => {
header={device.name ?? ''}
headerDescription={intl.formatMessage({ id: 'content__activated' })}
secondaryActionTranslationId="action__close"
onSecondaryActionPress={resetToRoot}
onSecondaryActionPress={openRootHome}
staticChildrenProps={{
flex: '1',
p: 6,
Expand Down

0 comments on commit 590c2ba

Please sign in to comment.