-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #744 from vultisig/feat/join-swap
Display swap information when joining a swap transaction.
- Loading branch information
Showing
13 changed files
with
148 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const oneInchName = '1inch'; |
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { matchRecordUnion } from '../../../lib/utils/matchRecordUnion'; | ||
import { oneInchName } from '../oneInch/config'; | ||
import { SwapQuote } from './SwapQuote'; | ||
|
||
export const getSwapQuoteProviderName = (quote: SwapQuote) => { | ||
return matchRecordUnion(quote, { | ||
native: ({ swapChain }) => swapChain, | ||
oneInch: () => '1inch', | ||
oneInch: () => oneInchName, | ||
}); | ||
}; |
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
16 changes: 3 additions & 13 deletions
16
frontend/src/vault/keysign/join/verify/KeysignTxOverview.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 |
---|---|---|
@@ -1,24 +1,14 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { TxOverviewPanel } from '../../../../chain/tx/components/TxOverviewPanel'; | ||
import { TxOverviewPrimaryRow } from '../../../../chain/tx/components/TxOverviewPrimaryRow'; | ||
import { shouldBePresent } from '../../../../lib/utils/assert/shouldBePresent'; | ||
import { KeysignSwapTxInfo } from '../../../swap/keysign/KeysignSwapTxInfo'; | ||
import { KeysignTxPrimaryInfo } from '../../shared/KeysignTxPrimaryInfo'; | ||
import { useKeysignPayload } from '../../shared/state/keysignPayload'; | ||
|
||
export const KeysignTxOverview = () => { | ||
const { coin: potentialCoin } = useKeysignPayload(); | ||
|
||
const coin = shouldBePresent(potentialCoin); | ||
|
||
const { address } = shouldBePresent(coin); | ||
|
||
const { t } = useTranslation(); | ||
const { swapPayload } = useKeysignPayload(); | ||
|
||
return ( | ||
<TxOverviewPanel> | ||
<TxOverviewPrimaryRow title={t('from')}>{address}</TxOverviewPrimaryRow> | ||
<KeysignTxPrimaryInfo /> | ||
{swapPayload.value ? <KeysignSwapTxInfo /> : <KeysignTxPrimaryInfo />} | ||
</TxOverviewPanel> | ||
); | ||
}; |
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,78 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { toKeysignSwapPayload } from '../../../chain/keysign/KeysignSwapPayload'; | ||
import { oneInchName } from '../../../chain/swap/oneInch/config'; | ||
import { TxOverviewPrimaryRow } from '../../../chain/tx/components/TxOverviewPrimaryRow'; | ||
import { fromChainAmount } from '../../../chain/utils/fromChainAmount'; | ||
import { withoutUndefined } from '../../../lib/utils/array/withoutUndefined'; | ||
import { formatAmount } from '../../../lib/utils/formatAmount'; | ||
import { getDiscriminatedUnionValue } from '../../../lib/utils/getDiscriminatedUnionValue'; | ||
import { matchDiscriminatedUnion } from '../../../lib/utils/matchDiscriminatedUnion'; | ||
import { assertField } from '../../../lib/utils/record/assertField'; | ||
import { Chain } from '../../../model/chain'; | ||
import { useKeysignPayload } from '../../keysign/shared/state/keysignPayload'; | ||
|
||
export const KeysignSwapTxInfo = () => { | ||
const payload = useKeysignPayload(); | ||
|
||
const { erc20ApprovePayload, toAmount: fromAmount } = payload; | ||
|
||
const fromCoin = assertField(payload, 'coin'); | ||
|
||
const { t } = useTranslation(); | ||
|
||
const action = withoutUndefined([ | ||
erc20ApprovePayload ? t('approve') : undefined, | ||
t('swap'), | ||
]).join(` ${t('and')} `); | ||
|
||
const swapPayload = toKeysignSwapPayload(payload.swapPayload); | ||
|
||
const swapPayloadValue = getDiscriminatedUnionValue( | ||
swapPayload, | ||
'case', | ||
'value', | ||
swapPayload.case | ||
); | ||
|
||
const toCoin = assertField(swapPayloadValue, 'toCoin'); | ||
const toAmount = Number(swapPayloadValue.toAmountDecimal); | ||
|
||
const provider = matchDiscriminatedUnion(swapPayload, 'case', 'value', { | ||
thorchainSwapPayload: () => Chain.THORChain, | ||
mayachainSwapPayload: () => Chain.MayaChain, | ||
oneinchSwapPayload: () => oneInchName, | ||
}); | ||
|
||
return ( | ||
<> | ||
<TxOverviewPrimaryRow title={t('action')}>{action}</TxOverviewPrimaryRow> | ||
<TxOverviewPrimaryRow title={t('provider')}> | ||
{provider} | ||
</TxOverviewPrimaryRow> | ||
<TxOverviewPrimaryRow title={t('from_asset')}> | ||
{formatAmount( | ||
fromChainAmount(fromAmount, fromCoin.decimals), | ||
fromCoin.ticker | ||
)} | ||
</TxOverviewPrimaryRow> | ||
<TxOverviewPrimaryRow title={t('to_asset')}> | ||
{formatAmount(toAmount, toCoin.ticker)} | ||
</TxOverviewPrimaryRow> | ||
|
||
{erc20ApprovePayload && ( | ||
<> | ||
<TxOverviewPrimaryRow title={t('allowance_spender')}> | ||
{erc20ApprovePayload.spender} | ||
</TxOverviewPrimaryRow> | ||
<TxOverviewPrimaryRow title={t('allowance_amount')}> | ||
{formatAmount( | ||
fromChainAmount(erc20ApprovePayload.amount, fromCoin.decimals), | ||
fromCoin.ticker | ||
)} | ||
</TxOverviewPrimaryRow> | ||
</> | ||
)} | ||
</> | ||
); | ||
}; |