Skip to content

Commit

Permalink
Merge pull request #36 from suisin-deriv/suisin/76931/ts_migration_st…
Browse files Browse the repository at this point in the history
…atic_url

Suisin/refactor: ts migration for static url
  • Loading branch information
niloofar-deriv committed Jan 11, 2023
2 parents 51a71b8 + fd3ed54 commit 11e7b31
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PlatformContext } from '@deriv/shared';
import Icon from '../icon/icon';
import Button from '../button/button';
import Text from '../text';
import { TPlatformContext } from '../static-url/static-url';

type TSendEmailTemplate = {
className?: string;
Expand Down Expand Up @@ -32,7 +33,7 @@ const SendEmailTemplate = ({
const [is_email_not_received_clicked, setIsEmailNotReceivedClicked] = React.useState(false);
const [is_resend_btn_disabled, setIsResendBtnDisabled] = React.useState(false);
const [resend_email_btn_text, setResendEmailBtnText] = React.useState(txt_resend);
const { is_appstore } = React.useContext<{ is_pre_appstore: boolean; is_appstore: boolean }>(PlatformContext);
const { is_appstore } = React.useContext<TPlatformContext>(PlatformContext);

const timeout_limit = resend_timeout || 60;
let resend_interval: number;
Expand Down
3 changes: 0 additions & 3 deletions packages/components/src/components/static-url/index.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/components/src/components/static-url/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import StaticUrl from './static-url';

export default StaticUrl;
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import React from 'react';
import { getStaticUrl, PlatformContext, setUrlLanguage } from '@deriv/shared';
import { getLanguage } from '@deriv/translations';

const StaticUrl = ({ href, is_document, children, ...props }) => {
const { is_appstore } = React.useContext(PlatformContext);
export type TPlatformContext = {
is_appstore?: boolean;
is_pre_appstore?: boolean;
};

type TStaticUrl = {
href?: string;
is_document?: boolean;
};

const StaticUrl = ({ href, is_document, children, ...props }: React.PropsWithChildren<TStaticUrl>) => {
const { is_appstore } = React.useContext<TPlatformContext>(PlatformContext);
const getHref = () => {
setUrlLanguage(getLanguage());
return getStaticUrl(href, { is_appstore }, is_document);
Expand Down
7 changes: 6 additions & 1 deletion packages/shared/src/utils/platform/platform-context.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React from 'react';

export const PlatformContext = React.createContext({} as { is_pre_appstore: boolean; is_appstore: boolean });
export type TPlatformContext = {
is_appstore?: boolean;
is_pre_appstore?: boolean;
};

export const PlatformContext = React.createContext<TPlatformContext>({});

PlatformContext.displayName = 'DerivAppStorePlatformContext';

0 comments on commit 11e7b31

Please sign in to comment.