-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hamza/90545/responsive user awareness (#7922)
* feat: responsive user awareness v1.0 * feat: responsive user awareness v1.1 * feat: responsive user awareness v1.2 * feat: responsive user awareness v1.3 * feat: responsive user awareness v1.3 * feat: responsive user awareness v1.4 * feat: responsive user awareness v1.5 * feat: responsive user awareness v1.6 * refactor: review code + tsmigration * refactor: removed the unused props * refactor: removed the unused props v1.2 * refactor: alias added v1.3 * fix: successfully added in the text * fix: successfully added in the text + Standardization V1.2 * fix: successfully added in the text + Standardization V1.3 * fix: successfully added in the text + Standardization V1.3.1 * fix: language switcher css (#8084) Co-authored-by: yashim-deriv <yashim@deriv.com> * fix: placeholder signup modal typo (#8095) * thisyahlen/fix: disable language button till language is fully loaded (#8089) * fix: disable language button till language is fully loaded * fix: add mockstore * fix: responsive * fix: remove unused css * fix: css * fix: 🐛 button not disabled for account signup (#8103) * Amina/fix: set citizen on account (#8102) * fix: set citizen on account * chore: trigger circleci * fix: set citizen on account --------- Co-authored-by: Matin shafiei <matin@deriv.com> Co-authored-by: thisyahlen <104053934+thisyahlen-deriv@users.noreply.github.com> Co-authored-by: yashim-deriv <yashim@deriv.com> Co-authored-by: Aizad Ridzo <103104395+aizad-deriv@users.noreply.github.com> Co-authored-by: Likhith Kolayari <98398322+likhith-deriv@users.noreply.github.com> Co-authored-by: amina-deriv <84661147+amina-deriv@users.noreply.github.com>
- Loading branch information
1 parent
002d125
commit 3cebbba
Showing
14 changed files
with
217 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { TRootStore } from '@deriv/stores/types'; | ||
import type TradeStore from './src/Stores/Modules/Trading/trade-store'; | ||
|
||
type TToastBoxListItem = { | ||
contract_category: string; | ||
contract_types: [ | ||
{ | ||
text: string; | ||
value: string; | ||
} | ||
]; | ||
}; | ||
|
||
type TToastBoxObject = { | ||
key?: boolean; | ||
buy_price?: number; | ||
currency?: string; | ||
contract_type?: string; | ||
list?: TToastBoxListItem[]; | ||
}; | ||
|
||
type TOverrideTradeStore = Omit<TradeStore, 'clearContractPurchaseToastBox' | 'contract_purchase_toast_box'> & { | ||
clearContractPurchaseToastBox: () => void; | ||
contract_purchase_toast_box: TToastBoxObject; | ||
}; | ||
|
||
declare module '@deriv/stores' { | ||
export function useStore(): TRootStore & { | ||
modules: { | ||
trade: TOverrideTradeStore; | ||
}; | ||
}; | ||
} |
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
63 changes: 63 additions & 0 deletions
63
...ules/SmartChart/Components/BuyToastNotification/__tests__/buy-toast-notification.spec.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,63 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import BuyToastNotification from '../../buy-toast-notification'; | ||
import { mockStore, StoreProvider } from '@deriv/stores'; | ||
|
||
describe('BuyToastNotification component', () => { | ||
const mockActionToastbox = { | ||
buy_price: '100', | ||
currency: 'USD', | ||
contract_type: 'rise_fall', | ||
list: [ | ||
{ contract_category: 'up_down', contract_types: [{ text: 'Rise/Fall', value: 'rise_fall' }] }, | ||
{ contract_category: 'high_low', contract_types: [{ text: 'Higher/Lower', value: 'higher_lower' }] }, | ||
], | ||
key: true, | ||
}; | ||
|
||
const mock = mockStore({ | ||
modules: { | ||
trade: { | ||
contract_purchase_toast_box: mockActionToastbox, | ||
clearContractPurchaseToastBox: jest.fn(), | ||
}, | ||
}, | ||
}); | ||
|
||
let modal_root_el: HTMLDivElement; | ||
|
||
beforeAll(() => { | ||
modal_root_el = document.createElement('div'); | ||
modal_root_el.setAttribute('id', 'popup_root'); | ||
document.body.appendChild(modal_root_el); | ||
}); | ||
|
||
afterAll(() => { | ||
document.body.removeChild(modal_root_el); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.useFakeTimers(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.useRealTimers(); | ||
}); | ||
|
||
it('should render the notification ', () => { | ||
render(<BuyToastNotification />, { | ||
wrapper: ({ children }) => <StoreProvider store={mock}>{children}</StoreProvider>, | ||
}); | ||
|
||
expect(modal_root_el).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call clearContractPurchaseToastBox after 4 seconds', () => { | ||
render(<BuyToastNotification />, { | ||
wrapper: ({ children }) => <StoreProvider store={mock}>{children}</StoreProvider>, | ||
}); | ||
|
||
jest.advanceTimersByTime(4000); | ||
expect(mock.modules.trade.clearContractPurchaseToastBox).toHaveBeenCalled(); | ||
}); | ||
}); |
60 changes: 60 additions & 0 deletions
60
packages/trader/src/Modules/SmartChart/Components/buy-toast-notification.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,60 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { MobileWrapper, Toast, Text } from '@deriv/components'; | ||
import { Localize } from '@deriv/translations'; | ||
import { findContractCategory } from 'Modules/Trading/Helpers/contract-type'; | ||
import { observer, useStore } from '@deriv/stores'; | ||
|
||
type TContractType = { | ||
text: string; | ||
value: string; | ||
}; | ||
|
||
const BuyToastNotification = observer(() => { | ||
const portal = document.getElementById('popup_root'); | ||
const { modules } = useStore(); | ||
const { trade } = modules; | ||
const { contract_purchase_toast_box, clearContractPurchaseToastBox } = trade; | ||
|
||
React.useEffect(() => { | ||
const timeout = setTimeout(() => { | ||
clearContractPurchaseToastBox(); | ||
}, 4000); | ||
|
||
return () => { | ||
clearTimeout(timeout); | ||
}; | ||
}, [clearContractPurchaseToastBox, contract_purchase_toast_box]); | ||
|
||
if (!portal || !contract_purchase_toast_box) return <React.Fragment />; | ||
|
||
const { buy_price, currency, contract_type, list } = contract_purchase_toast_box; | ||
const active_trade_type = { value: contract_type }; | ||
|
||
const trade_type_name = findContractCategory(list, active_trade_type)?.contract_types?.find( | ||
(item: TContractType) => item.value === contract_type | ||
).text; | ||
|
||
return ReactDOM.createPortal( | ||
<MobileWrapper> | ||
<Toast | ||
className='dc-toast-popup-mobile' | ||
is_open={!!contract_purchase_toast_box.key} | ||
timeout={0} | ||
type='notification' | ||
> | ||
<Text as='p' size='xxs' className='dc-toast__notification'> | ||
<Localize | ||
i18n_default_text='The purchase of <0>{{trade_type_name}} contract</0> has been completed successfully for the amount of <0> {{buy_price}} {{currency}}</0>' | ||
components={[<strong key={0} />]} | ||
values={{ trade_type_name, buy_price, currency }} | ||
shouldUnescape | ||
/> | ||
</Text> | ||
</Toast> | ||
</MobileWrapper>, | ||
portal | ||
); | ||
}); | ||
|
||
export default BuyToastNotification; |
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