Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kollider): routes #2309

Merged
merged 11 commits into from
May 3, 2023
2 changes: 1 addition & 1 deletion src/app/components/ConnectorForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function ConnectorForm({
just one place
*/}
{typeof title === "string" ? (
<h1 className="text-2xl font-bold dark:text-white">{title}</h1>
<h1 className="`text-2xl font-bold dark:text-white">{title}</h1>
) : (
title
)}
Expand Down
80 changes: 53 additions & 27 deletions src/app/router/Options/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,58 @@ import ChooseConnector from "~/app/screens/connectors/ChooseConnector";
import ChooseConnectorPath from "~/app/screens/connectors/ChooseConnectorPath";
import i18n from "~/i18n/i18nConfig";

function renderRoutes(
routes:
| {
path: string;
element?: JSX.Element;
title: string;
logo: string;
children?: {
index?: boolean;
element: JSX.Element;
path?: string;
}[];
}[]
| {
index?: boolean;
element: JSX.Element;
path?: string;
}[]
) {
return routes.map((route) => {
if ("children" in route && route.children) {
reneaaron marked this conversation as resolved.
Show resolved Hide resolved
if ("element" in route && route.element) {
return (
<Route key={route.path} path={route.path}>
<Route index element={route.element} />
{renderRoutes(route.children)}
</Route>
);
} else {
let indexRoute;
const indexRouteIndex = route.children.findIndex(
(childRoute) => childRoute.index === true
);

if (indexRouteIndex !== -1) {
indexRoute = route.children.splice(indexRouteIndex, 1)[0];
return (
<Route key={route.path} path={route.path}>
<Route index element={indexRoute.element} />
{renderRoutes(route.children)}
</Route>
);
}
}
} else {
return (
<Route key={route.path} path={route.path} element={route.element} />
);
}
});
}

function Options() {
const connectorRoutes = getConnectorRoutes();

Expand Down Expand Up @@ -99,33 +151,7 @@ function Options() {
/>
}
/>
{connectorRoutes.map((connectorRoute) => {
if (connectorRoute.children) {
return (
<Route
key={connectorRoute.path}
path={connectorRoute.path}
>
<Route index element={connectorRoute.element} />
{connectorRoute.children.map((connectorRoute) => (
<Route
key={connectorRoute.path}
path={connectorRoute.path}
element={connectorRoute.element}
/>
))}
</Route>
);
} else {
return (
<Route
key={connectorRoute.path}
path={connectorRoute.path}
element={connectorRoute.element}
/>
);
}
})}
{renderRoutes(connectorRoutes)}
</Route>
</Route>
<Route index element={<Accounts />} />
Expand Down
7 changes: 6 additions & 1 deletion src/app/router/Welcome/Welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ const connectorRoutes = getConnectorRoutes();
function getRoutes(
connectorRoutes: {
path: string;
element: JSX.Element;
element?: JSX.Element;
title: string;
logo: string;
children?: {
index?: boolean;
element: JSX.Element;
path?: string;
}[];
}[]
): RouteObject[] {
return [
Expand Down
5 changes: 4 additions & 1 deletion src/app/router/connectorRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ function getConnectorRoutes() {
},
{
path: "kollider",
element: <ConnectKollider variant="select" />,
title: i18n.t("translation:choose_connector.kollider.title"),
description: i18n.t("translation:choose_connector.kollider.description"),
logo: kolliderLogo,
children: [
{
index: true,
element: <ConnectKollider variant="select" />,
},
{
path: "create",
element: <ConnectKollider variant="create" />,
Expand Down
22 changes: 3 additions & 19 deletions src/app/screens/connectors/ConnectKollider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Select from "@components/form/Select";
import TextField from "@components/form/TextField";
import ConnectionErrorToast from "@components/toasts/ConnectionErrorToast";
import { useState } from "react";
import { Trans, useTranslation } from "react-i18next";
import { useTranslation } from "react-i18next";
import { Link, useNavigate } from "react-router-dom";
import { toast } from "react-toastify";
import { ACCOUNT_CURRENCIES } from "~/common/constants";
Expand Down Expand Up @@ -158,25 +158,9 @@ export default function ConnectKollidier({ variant }: Props) {
) : (
<ConnectorForm
title={t(`${variant}.title`)}
description={
variant === "create" ? (
t(`create.description`)
) : (
<Trans
i18nKey={"login.description"}
t={t}
components={[
// eslint-disable-next-line react/jsx-key
<Link
reneaaron marked this conversation as resolved.
Show resolved Hide resolved
className="underline"
to="/accounts/new/choose-connector/kollider/create"
></Link>,
]}
/>
)
}
logo={logo}
description={variant === "create" ? t(`create.description`) : null}
submitLoading={loading}
logo={logo}
submitDisabled={
loading ||
formData.password === "" ||
Expand Down
1 change: 1 addition & 0 deletions src/extension/background-script/connectors/kollider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ export default class Kollider implements Connector {
method,
url: `${API_URL}${path}`,
responseType: "json",
adapter: fetchAdapter,
headers: {
...defaultHeaders,
Authorization: `${this.access_token}`,
Expand Down
3 changes: 1 addition & 2 deletions src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@
"description": "Create a new Kollider account to send, receive and trade Bitcoin."
},
"login": {
"title": "Connect to your Kollider account",
"description": "Don't have an account already? <0>Sign up</0> now!"
"title": "Connect to your Kollider account"
},
"username": {
"label": "Username"
Expand Down