Skip to content

Commit

Permalink
feat: add inscription id and symbol to send rune and psbt screen (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedeerbes committed May 17, 2024
1 parent f27341f commit a941037
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 67 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@playwright/test": "^1.43.1",
"@react-spring/web": "^9.6.1",
"@scure/btc-signer": "1.2.1",
"@secretkeylabs/xverse-core": "13.6.7",
"@secretkeylabs/xverse-core": "13.6.7-60156af",
"@stacks/connect": "7.4.1",
"@stacks/stacks-blockchain-api-types": "6.1.1",
"@stacks/transactions": "6.13.1",
Expand Down
6 changes: 1 addition & 5 deletions src/app/components/confirmBtcTransaction/burnSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ function BurnSection({ burns }: Props) {
</Header>
{burns.map((burn) => (
<RowContainer key={burn.runeName}>
<RuneAmount
tokenName={burn.runeName}
amount={String(burn.amount)}
divisibility={burn.divisibility}
/>
<RuneAmount rune={burn} />
</RowContainer>
))}
</Container>
Expand Down
6 changes: 1 addition & 5 deletions src/app/components/confirmBtcTransaction/delegateSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ function DelegateSection({ delegations }: Props) {
</Header>
{delegations.map((delegation) => (
<RowContainer key={delegation.runeName}>
<RuneAmount
tokenName={delegation.runeName}
amount={String(delegation.amount)}
divisibility={delegation.divisibility}
/>
<RuneAmount rune={delegation} />
</RowContainer>
))}
<WarningButton type="button" onClick={() => setShowDelegationInfo((prevState) => !prevState)}>
Expand Down
21 changes: 8 additions & 13 deletions src/app/components/confirmBtcTransaction/itemRow/runeAmount.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mapRuneNameToPlaceholder } from '@components/confirmBtcTransaction/utils';
import TokenImage from '@components/tokenImage';
import { RuneBase } from '@secretkeylabs/xverse-core';
import Avatar from '@ui-library/avatar';
import { StyledP } from '@ui-library/common.styled';
import { ftDecimals, getTicker } from '@utils/helper';
Expand Down Expand Up @@ -40,28 +41,22 @@ const StyledPRight = styled(StyledP)`
`;

type Props = {
tokenName: string;
amount: string;
divisibility: number;
rune: RuneBase;
hasSufficientBalance?: boolean;
};

export default function RuneAmount({
tokenName,
amount,
divisibility,
hasSufficientBalance = true,
}: Props) {
export default function RuneAmount({ rune, hasSufficientBalance = true }: Props) {
const { t } = useTranslation('translation', { keyPrefix: 'CONFIRM_TRANSACTION' });
const amountWithDecimals = ftDecimals(amount, divisibility);
const { runeName, amount, divisibility, symbol, inscriptionId } = rune;
const amountWithDecimals = ftDecimals(String(amount), divisibility);
return (
<Container>
<AvatarContainer>
<Avatar
src={
<TokenImage
currency="FT"
fungibleToken={mapRuneNameToPlaceholder(tokenName)}
fungibleToken={mapRuneNameToPlaceholder(runeName, symbol, inscriptionId)}
showProtocolIcon={false}
loading={false}
size={32}
Expand All @@ -78,7 +73,7 @@ export default function RuneAmount({
value={amountWithDecimals}
displayType="text"
thousandSeparator
suffix={` ${getTicker(tokenName)}`}
suffix={` ${symbol}`}
renderText={(value: string) => (
<StyledPRight
typography="body_medium_m"
Expand All @@ -90,7 +85,7 @@ export default function RuneAmount({
/>
</Row>
<StyledP typography="body_medium_s" color="white_400">
{tokenName}
{runeName}
</StyledP>
</Column>
</Container>
Expand Down
12 changes: 2 additions & 10 deletions src/app/components/confirmBtcTransaction/receiveSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ function ReceiveSection({
{showOrdinalRunes &&
ordinalRuneReceipts.map((receipt) => (
<RowContainer key={receipt.runeName}>
<RuneAmount
tokenName={receipt.runeName}
amount={String(receipt.amount)}
divisibility={receipt.divisibility}
/>
<RuneAmount rune={receipt} />
</RowContainer>
))}
{areInscriptionRareSatsInOrdinal && (
Expand Down Expand Up @@ -157,11 +153,7 @@ function ReceiveSection({
{showPaymentRunes &&
paymentRuneReceipts.map((receipt) => (
<RowContainer key={receipt.runeName}>
<RuneAmount
tokenName={receipt.runeName}
amount={String(receipt.amount)}
divisibility={receipt.divisibility}
/>
<RuneAmount rune={receipt} />
</RowContainer>
))}
{amountIsBiggerThanZero && (
Expand Down
7 changes: 1 addition & 6 deletions src/app/components/confirmBtcTransaction/transferSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,7 @@ function TransferSection({
transactionIsFinal &&
runeTransfers?.map((transfer) => (
<RowContainer key={transfer.runeName}>
<RuneAmount
tokenName={transfer.runeName}
amount={String(transfer.amount)}
divisibility={transfer.divisibility}
hasSufficientBalance={transfer.hasSufficientBalance}
/>
<RuneAmount rune={transfer} hasSufficientBalance={transfer.hasSufficientBalance} />
</RowContainer>
))
}
Expand Down
8 changes: 7 additions & 1 deletion src/app/components/confirmBtcTransaction/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,18 @@ export const getSatRangesWithInscriptions = ({
return { satRanges: satRangesArray, totalExoticSats };
};

export const mapRuneNameToPlaceholder = (runeName: string): FungibleToken => ({
export const mapRuneNameToPlaceholder = (
runeName: string,
symbol: string,
inscriptionId: string,
): FungibleToken => ({
protocol: 'runes',
name: runeName,
assetName: '',
balance: '',
principal: '',
total_received: '',
total_sent: '',
runeSymbol: symbol,
runeInscriptionId: inscriptionId,
});
21 changes: 8 additions & 13 deletions src/app/components/tokenImage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import RunesIcon from '@assets/img/transactions/runes.svg';
import { StyledBarLoader } from '@components/tilesSkeletonLoader';
import useWalletSelector from '@hooks/useWalletSelector';
import { FungibleToken } from '@secretkeylabs/xverse-core';
import { ORDINALS_URL } from '@secretkeylabs/xverse-core/constant';
import { CurrencyTypes } from '@utils/constants';
import { CurrencyTypes, XVERSE_ORDIVIEW_URL } from '@utils/constants';
import { getTicker } from '@utils/helper';
import { useCallback } from 'react';
import styled from 'styled-components';
Expand Down Expand Up @@ -118,17 +117,13 @@ export default function TokenImage({
return <TickerImage data-testid="token-image" size={size} src={fungibleToken.image} />;
}
if (fungibleToken.runeInscriptionId) {
const img = new Image(); // determine if valid image
img.src = ORDINALS_URL(network.type, fungibleToken.runeInscriptionId);
if (img.complete) {
return (
<TickerImage
data-testid="token-image"
size={size}
src={ORDINALS_URL(network.type, fungibleToken.runeInscriptionId)}
/>
);
}
return (
<TickerImage
data-testid="token-image"
size={size}
src={`${XVERSE_ORDIVIEW_URL(network.type)}/thumbnail/${fungibleToken.runeInscriptionId}`}
/>
);
}
if (fungibleToken.runeSymbol) {
return (
Expand Down
7 changes: 1 addition & 6 deletions src/app/screens/restoreFunds/recoverRunes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,7 @@ function RecoverRunes() {
<ScrollContainer>
{(runeSummary?.transfers ?? []).map((transfer) => (
<RowContainer key={transfer.runeName}>
<RuneAmount
tokenName={transfer.runeName}
amount={String(transfer.amount)}
divisibility={transfer.divisibility}
hasSufficientBalance={transfer.hasSufficientBalance}
/>
<RuneAmount rune={transfer} hasSufficientBalance={transfer.hasSufficientBalance} />
</RowContainer>
))}
</ScrollContainer>
Expand Down

0 comments on commit a941037

Please sign in to comment.