-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8e728c
commit 5ba38ab
Showing
5 changed files
with
105 additions
and
0 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
69 changes: 69 additions & 0 deletions
69
packages/suite/src/views/wallet/trading/common/TradingForm/TradingFormOfferOTC.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,69 @@ | ||
import { TradingTradeBuySellType, invityAPI } from '@suite-common/trading'; | ||
import { Banner, Text } from '@trezor/components'; | ||
import { spacings } from '@trezor/theme'; | ||
|
||
import { Translation, TrezorLink } from 'src/components/suite'; | ||
import { useTradingFormContext } from 'src/hooks/wallet/trading/form/useTradingCommonForm'; | ||
import { isTradingBuyContext } from 'src/utils/wallet/trading/tradingTypingUtils'; | ||
|
||
export const TradingFormOfferOTC = () => { | ||
const context = useTradingFormContext<TradingTradeBuySellType>(); | ||
const { amountInCrypto } = context.getValues(); | ||
const fiatAmount = isTradingBuyContext(context) | ||
? context.getValues().fiatInput | ||
: context.getValues().outputs[0].fiat; | ||
const currencySelect = isTradingBuyContext(context) | ||
? context.getValues().currencySelect.value | ||
: context.getValues().outputs[0].currency.value; | ||
|
||
// constants will be refactor to be more dynamic in the future | ||
const ALLOWED_FIAT_CURRENCIES = ['usd', 'eur']; | ||
const FIAT_AMOUNT_ALLOWANCE = '50001'; | ||
|
||
const isCurrencyAllowed = ALLOWED_FIAT_CURRENCIES.includes(currencySelect); | ||
|
||
if ( | ||
amountInCrypto || | ||
!isCurrencyAllowed || | ||
!fiatAmount || | ||
Number(fiatAmount) < Number(FIAT_AMOUNT_ALLOWANCE) | ||
) { | ||
return null; | ||
} | ||
|
||
const handleClick = async () => { | ||
const otcData = await invityAPI.getOTCData(); | ||
|
||
if (!otcData) return; | ||
|
||
const apiUrl = new URL(otcData.apiUrl); | ||
const params = new URLSearchParams({ | ||
widget_id: otcData.idWidget, | ||
otc_id: otcData.idOtcUser, | ||
fiat_amount: fiatAmount, | ||
fiat_currency: currencySelect, | ||
type: context.type, | ||
}); | ||
|
||
apiUrl.search = params.toString(); | ||
|
||
window.open(apiUrl, '_blank'); | ||
}; | ||
|
||
return ( | ||
<Banner variant="info"> | ||
<Text margin={{ bottom: spacings.xxs }}> | ||
<Translation id="TR_TRADING_OTC_INFO" />{' '} | ||
<TrezorLink onClick={handleClick} href="" target="_blank" typographyStyle="hint"> | ||
<Translation | ||
id={ | ||
context.type === 'buy' | ||
? 'TR_TRADING_OTC_LINK_BUY' | ||
: 'TR_TRADING_OTC_LINK_SELL' | ||
} | ||
/> | ||
</TrezorLink> | ||
</Text> | ||
</Banner> | ||
); | ||
}; |
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