Skip to content

Commit

Permalink
feat: Translation support for connect and account modal (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
memoyil authored Aug 30, 2021
1 parent f1905af commit 6d97f2e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { renderWithTheme } from "../../testHelpers";
import ConnectModal from "../../widgets/WalletModal/ConnectModal";

it("renders ConnectModal correctly", () => {
const { asFragment } = renderWithTheme(<ConnectModal login={noop} />);
const { asFragment } = renderWithTheme(<ConnectModal login={noop} t={(key: string) => key} />);
expect(asFragment()).toMatchInlineSnapshot(`
<DocumentFragment>
.c0 {
Expand Down Expand Up @@ -651,7 +651,7 @@ it("renders ConnectModal correctly", () => {
class="c21"
color="textSubtle"
>
Haven't got a crypto wallet yet?
Havent got a crypto wallet yet?
</p>
<a
class="c22"
Expand Down
11 changes: 6 additions & 5 deletions packages/pancake-uikit/src/widgets/WalletModal/AccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ interface Props {
account: string;
logout: () => void;
onDismiss?: () => void;
t: (key: string) => string;
}

const AccountModal: React.FC<Props> = ({ account, logout, onDismiss = () => null }) => (
<Modal title="Your wallet" onDismiss={onDismiss}>
const AccountModal: React.FC<Props> = ({ account, logout, onDismiss = () => null, t }) => (
<Modal title={t("Your wallet")} onDismiss={onDismiss}>
<Text
fontSize="20px"
bold
Expand All @@ -24,9 +25,9 @@ const AccountModal: React.FC<Props> = ({ account, logout, onDismiss = () => null
</Text>
<Flex mb="32px">
<LinkExternal small href={`https://bscscan.com/address/${account}`} mr="16px">
View on BscScan
{t("View on BscScan")}
</LinkExternal>
<CopyToClipboard toCopy={account}>Copy Address</CopyToClipboard>
<CopyToClipboard toCopy={account}>{t("Copy Address")}</CopyToClipboard>
</Flex>
<Flex justifyContent="center">
<Button
Expand All @@ -38,7 +39,7 @@ const AccountModal: React.FC<Props> = ({ account, logout, onDismiss = () => null
onDismiss();
}}
>
Logout
{t("Logout")}
</Button>
</Flex>
</Modal>
Expand Down
11 changes: 6 additions & 5 deletions packages/pancake-uikit/src/widgets/WalletModal/ConnectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface Props {
login: Login;
onDismiss?: () => void;
displayCount?: number;
t: (key: string) => string;
}

const WalletWrapper = styled(Box)`
Expand Down Expand Up @@ -48,7 +49,7 @@ const getPreferredConfig = (walletConfig: Config[]) => {
];
};

const ConnectModal: React.FC<Props> = ({ login, onDismiss = () => null, displayCount = 3 }) => {
const ConnectModal: React.FC<Props> = ({ login, onDismiss = () => null, displayCount = 3, t }) => {
const [showMore, setShowMore] = useState(false);
const theme = useTheme();
const sortedConfig = getPreferredConfig(config);
Expand All @@ -58,7 +59,7 @@ const ConnectModal: React.FC<Props> = ({ login, onDismiss = () => null, displayC
<ModalContainer minWidth="320px">
<ModalHeader background={getThemeValue("colors.gradients.bubblegum")(theme)}>
<ModalTitle>
<Heading>Connect Wallet</Heading>
<Heading>{t("Connect Wallet")}</Heading>
</ModalTitle>
<ModalCloseButton onDismiss={onDismiss} />
</ModalHeader>
Expand All @@ -70,12 +71,12 @@ const ConnectModal: React.FC<Props> = ({ login, onDismiss = () => null, displayC
<WalletCard walletConfig={wallet} login={login} onDismiss={onDismiss} />
</Box>
))}
{!showMore && <MoreWalletCard onClick={() => setShowMore(true)} />}
{!showMore && <MoreWalletCard t={t} onClick={() => setShowMore(true)} />}
</Grid>
</WalletWrapper>
<Box p="24px">
<Text textAlign="center" color="textSubtle" as="p" mb="16px">
Haven&#39;t got a crypto wallet yet?
{t("Havent got a crypto wallet yet?")}
</Text>
<Button
as="a"
Expand All @@ -84,7 +85,7 @@ const ConnectModal: React.FC<Props> = ({ login, onDismiss = () => null, displayC
width="100%"
{...getExternalLinkProps()}
>
Learn How to Connect
{t("Learn How to Connect")}
</Button>
</Box>
</ModalBody>
Expand Down
8 changes: 6 additions & 2 deletions packages/pancake-uikit/src/widgets/WalletModal/WalletCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ const WalletButton = styled(Button).attrs({ width: "100%", variant: "text", py:
margin-right: auto;
`;

export const MoreWalletCard: React.FC<ButtonProps> = (props) => {
interface MoreWalletCardProps extends ButtonProps {
t: (key: string) => string;
}

export const MoreWalletCard: React.FC<MoreWalletCardProps> = ({ t, ...props }) => {
return (
<WalletButton variant="tertiary" {...props}>
<MoreHorizontal width="40px" mb="8px" color="textSubtle" />
<Text fontSize="14px">More</Text>
<Text fontSize="14px">{t("More")}</Text>
</WalletButton>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ interface ReturnType {
onPresentAccountModal: () => void;
}

const useWalletModal = (login: Login, logout: () => void, account?: string): ReturnType => {
const [onPresentConnectModal] = useModal(<ConnectModal login={login} />);
const [onPresentAccountModal] = useModal(<AccountModal account={account || ""} logout={logout} />);
const useWalletModal = (login: Login, logout: () => void, t: (key: string) => string, account?: string): ReturnType => {
const [onPresentConnectModal] = useModal(<ConnectModal login={login} t={t} />);
const [onPresentAccountModal] = useModal(<AccountModal account={account || ""} logout={logout} t={t} />);
return { onPresentConnectModal, onPresentAccountModal };
};

Expand Down

0 comments on commit 6d97f2e

Please sign in to comment.