-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add human readable transfers to history and queue (#2518)
* Add human readable transfers to history and queue * Format token value to adhere to the style guide * Fix failing tests * Fix mobile view
- Loading branch information
1 parent
2e062eb
commit b9a5842
Showing
13 changed files
with
178 additions
and
50 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
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,73 @@ | ||
import { | ||
type RichAddressFragment, | ||
type RichDecodedInfo, | ||
type RichTokenValueFragment, | ||
RichFragmentType, | ||
} from '@safe-global/safe-gateway-typescript-sdk/dist/types/human-description' | ||
import EthHashInfo from '@/components/common/EthHashInfo' | ||
import css from './styles.module.css' | ||
import useAddressBook from '@/hooks/useAddressBook' | ||
import TokenAmount from '@/components/common/TokenAmount' | ||
import React from 'react' | ||
import { type Transfer } from '@safe-global/safe-gateway-typescript-sdk' | ||
import { TransferTx } from '@/components/transactions/TxInfo' | ||
import { formatAmount } from '@/utils/formatNumber' | ||
|
||
const AddressFragment = ({ fragment }: { fragment: RichAddressFragment }) => { | ||
const addressBook = useAddressBook() | ||
|
||
return ( | ||
<div className={css.address}> | ||
<EthHashInfo address={fragment.value} name={addressBook[fragment.value]} avatarSize={20} /> | ||
</div> | ||
) | ||
} | ||
|
||
const TokenValueFragment = ({ fragment }: { fragment: RichTokenValueFragment }) => { | ||
const isUnlimitedApproval = fragment.value === 'unlimited' | ||
|
||
return ( | ||
<TokenAmount | ||
// formatAmount should ideally be done in the CGW or fragment should contain the raw value as well | ||
value={isUnlimitedApproval ? fragment.value : formatAmount(fragment.value)} | ||
direction={undefined} | ||
logoUri={fragment.logoUri || undefined} | ||
tokenSymbol={fragment.symbol || undefined} | ||
/> | ||
) | ||
} | ||
|
||
export const TransferDescription = ({ txInfo, isSendTx }: { txInfo: Transfer; isSendTx: boolean }) => { | ||
const action = isSendTx ? 'Send' : 'Receive' | ||
const direction = isSendTx ? 'to' : 'from' | ||
const address = isSendTx ? txInfo.recipient.value : txInfo.sender.value | ||
const name = isSendTx ? txInfo.recipient.name : txInfo.sender.name | ||
|
||
return ( | ||
<> | ||
{action} | ||
<TransferTx info={txInfo} omitSign={true} /> | ||
{direction} | ||
<div className={css.address}> | ||
<EthHashInfo address={address} name={name} avatarSize={20} /> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export const HumanDescription = ({ fragments }: RichDecodedInfo) => { | ||
return ( | ||
<> | ||
{fragments.map((fragment) => { | ||
switch (fragment.type) { | ||
case RichFragmentType.Text: | ||
return <span>{fragment.value}</span> | ||
case RichFragmentType.Address: | ||
return <AddressFragment fragment={fragment} /> | ||
case RichFragmentType.TokenValue: | ||
return <TokenValueFragment fragment={fragment} /> | ||
} | ||
})} | ||
</> | ||
) | ||
} |
30 changes: 30 additions & 0 deletions
30
src/components/transactions/HumanDescription/styles.module.css
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,30 @@ | ||
.summary { | ||
display: flex; | ||
gap: 8px; | ||
align-items: center; | ||
width: 100%; | ||
} | ||
|
||
/* TODO: This is a workaround to hide address in case there is a title */ | ||
.address div[title] + div { | ||
display: none; | ||
} | ||
|
||
.value { | ||
display: flex; | ||
align-items: center; | ||
font-weight: bold; | ||
gap: 4px; | ||
} | ||
|
||
.method { | ||
display: inline-flex; | ||
align-items: center; | ||
gap: 0.5em; | ||
} | ||
|
||
.wrapper { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 8px; | ||
} |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.txType { | ||
display: flex; | ||
align-items: center; | ||
flex-wrap: wrap; | ||
gap: var(--space-1); | ||
color: var(--color-text-primary); | ||
} |
Oops, something went wrong.