-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DTRA] Ahmad/DTRA-1705/Insufficient Balance And Not Logged in User Ac…
…tion Sheet (#16787) * chore: done * fix: fix * fix: test case * fix: adding in mockStore * chore: icon * chore: fix * fix: test case * fix: changing snakcase * chore: review comments * fix: review fix for signup * chore: fix * chore: fix
- Loading branch information
1 parent
dbe0633
commit d761e7f
Showing
16 changed files
with
358 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/trader/src/AppV2/Components/ServiceErrorSheet/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import './service-error-sheet.scss'; | ||
import ServiceErrorSheet from './service-error-sheet'; | ||
|
||
export default ServiceErrorSheet; |
43 changes: 43 additions & 0 deletions
43
packages/trader/src/AppV2/Components/ServiceErrorSheet/service-error-description.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
import { Localize } from '@deriv/translations'; | ||
import { Text } from '@deriv-com/quill-ui'; | ||
|
||
type ServiceErrorProps = { | ||
is_insufficient_balance: boolean; | ||
is_authorization_required: boolean; | ||
services_error: { message?: string }; | ||
}; | ||
|
||
const ServiceErrorDescription: React.FC<ServiceErrorProps> = ({ | ||
is_insufficient_balance, | ||
is_authorization_required, | ||
services_error, | ||
}) => { | ||
if (is_insufficient_balance) { | ||
return ( | ||
<> | ||
<Text size='lg' bold className='service-error-sheet__body__heading'> | ||
<Localize i18n_default_text='Insufficient balance' /> | ||
</Text> | ||
<Text>{services_error?.message || <Localize i18n_default_text='An error occurred.' />}</Text> | ||
</> | ||
); | ||
} | ||
|
||
if (is_authorization_required) { | ||
return ( | ||
<> | ||
<Text size='lg' bold className='service-error-sheet__body__heading'> | ||
<Localize i18n_default_text='Start trading with us' /> | ||
</Text> | ||
<Text> | ||
<Localize i18n_default_text='Log in or create a free account to place a trade.' /> | ||
</Text> | ||
</> | ||
); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
export default ServiceErrorDescription; |
11 changes: 11 additions & 0 deletions
11
packages/trader/src/AppV2/Components/ServiceErrorSheet/service-error-sheet.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.service-error-sheet { | ||
&__body { | ||
margin: var(--core-size-1200); | ||
&__heading { | ||
margin-bottom: var(--core-size-1200); | ||
} | ||
} | ||
&__footer { | ||
margin: var(--core-size-400); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
packages/trader/src/AppV2/Components/ServiceErrorSheet/service-error-sheet.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { observer, useStore } from '@deriv/stores'; | ||
import { ActionSheet, Text } from '@deriv-com/quill-ui'; | ||
import { getLanguage, Localize } from '@deriv/translations'; | ||
import { redirectToLogin } from '@deriv/shared'; | ||
import { useHistory } from 'react-router'; | ||
import { useSignupTrigger } from 'AppV2/Hooks/useSignupTrigger'; | ||
import ServiceErrorDescription from './service-error-description'; | ||
|
||
const ServiceErrorSheet = observer(() => { | ||
const [is_open, setIsOpen] = useState(false); | ||
const { common } = useStore(); | ||
const { services_error, resetServicesError } = common; | ||
const { handleSignup } = useSignupTrigger(); | ||
const history = useHistory(); | ||
|
||
const is_insufficient_balance = | ||
services_error.code === 'InsufficientBalance' || services_error.code === 'InvalidContractProposal'; | ||
const is_authorization_required = services_error.code === 'AuthorizationRequired' && services_error.type === 'buy'; | ||
|
||
useEffect(() => { | ||
if (is_insufficient_balance || is_authorization_required) { | ||
setIsOpen(true); | ||
} | ||
}, [services_error]); | ||
|
||
useEffect(() => { | ||
if (!is_open && services_error.code) { | ||
resetServicesError(); | ||
} | ||
}, [resetServicesError, is_open]); | ||
|
||
return ( | ||
<ActionSheet.Root | ||
className='service-error-sheet' | ||
isOpen={is_open} | ||
onClose={() => { | ||
if (services_error.code) { | ||
setIsOpen(false); | ||
} | ||
}} | ||
expandable={false} | ||
position='left' | ||
> | ||
<ActionSheet.Portal showHandlebar shouldCloseOnDrag> | ||
<div className='service-error-sheet__body'> | ||
<ServiceErrorDescription | ||
is_authorization_required={is_authorization_required} | ||
is_insufficient_balance={is_insufficient_balance} | ||
services_error={services_error} | ||
/> | ||
</div> | ||
<ActionSheet.Footer | ||
className='service-error-sheet__footer' | ||
alignment='vertical' | ||
{...(is_insufficient_balance | ||
? { | ||
primaryAction: { | ||
content: <Localize i18n_default_text='Deposit now' />, | ||
onAction: () => { | ||
resetServicesError(); | ||
history.push('/cashier/deposit'); | ||
}, | ||
}, | ||
primaryButtonColor: 'coral', | ||
} | ||
: {})} | ||
{...(is_authorization_required | ||
? { | ||
primaryAction: { | ||
content: <Localize i18n_default_text='Create free account' />, | ||
onAction: () => { | ||
resetServicesError(); | ||
handleSignup(); | ||
}, | ||
}, | ||
primaryButtonColor: 'coral', | ||
secondaryAction: { | ||
content: <Localize i18n_default_text='Login' />, | ||
onAction: () => { | ||
resetServicesError(); | ||
redirectToLogin(false, getLanguage()); | ||
}, | ||
}, | ||
} | ||
: {})} | ||
/> | ||
</ActionSheet.Portal> | ||
</ActionSheet.Root> | ||
); | ||
}); | ||
|
||
export default ServiceErrorSheet; |
Oops, something went wrong.