Skip to content

Commit

Permalink
fix: transaction details amount
Browse files Browse the repository at this point in the history
  • Loading branch information
beautyfree committed Nov 14, 2020
1 parent 7a4e16b commit 282d19e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/common/TransactionRow/TransactionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const TransactionRow: FunctionComponent<Props> = ({ signature, publicKey
);

const { mint } = tokenAccount?.parsed || { amount: 0 };
let { symbol } = usePopulateTokenInfo({ mint: mint?.toBase58(), includeSol: true });
let { symbol } = usePopulateTokenInfo({ mint: mint?.toBase58() });

const { type, lamports } = useDecodeSystemProgramInstructions(
transaction?.transaction.instructions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { styled } from 'linaria/react';
import { rgba } from 'polished';

import { Icon } from 'components/ui';
import { RootState } from 'store/types';
import { RootState, TokenAccount } from 'store/types';
import { useDecodeSystemProgramInstructions } from 'utils/hooks/instructions/useDecodeSystemProgramInstructions';
import { useDecodeTokenRegInstructions } from 'utils/hooks/instructions/useDecodeTokenRegInstractions';
import { usePopulateTokenInfo } from 'utils/hooks/usePopulateTokenInfo';

const Wrapper = styled.div`
position: relative;
Expand Down Expand Up @@ -134,15 +136,32 @@ export const TransactionDetailsModal: FunctionComponent<Props> = ({ signature, c
const transaction = useSelector(
(state: RootState) => state.entities.transactionsNormalized[signature],
);
const transactionAuthor = transaction?.transaction.signatures[0].publicKey.toBase58();
const tokenAccount: TokenAccount = useSelector(
(state: RootState) => state.entities.tokens.items[transactionAuthor],
);
const { mint } = tokenAccount?.parsed || { amount: 0 };
let { symbol } = usePopulateTokenInfo({ mint: mint?.toBase58() });

const { type, fromPubkey, lamports, toPubkey } = useDecodeSystemProgramInstructions(
transaction?.transaction.instructions,
);

const { transfer } = useDecodeTokenRegInstructions(transaction?.transaction.instructions);

if (!transaction) {
return null;
}

// TODO: dirty
let amount = 0;
if (type) {
symbol = 'SOL';
amount = (lamports || 0) / web3.LAMPORTS_PER_SOL;
} else if (transfer) {
amount = (transfer.amount || 0) / web3.LAMPORTS_PER_SOL;
}

return (
<Wrapper>
<Header>
Expand All @@ -157,8 +176,9 @@ export const TransactionDetailsModal: FunctionComponent<Props> = ({ signature, c
</Header>
<Content>
<StatusWrapper>
{/* <Value>+ 0,00344 BTC</Value> */}
<Value>{(lamports || 0) / web3.LAMPORTS_PER_SOL}</Value>
<Value>
{amount} {symbol}
</Value>
<Status>Completed</Status>
</StatusWrapper>
<FieldsWrapper>
Expand All @@ -168,18 +188,18 @@ export const TransactionDetailsModal: FunctionComponent<Props> = ({ signature, c
</FieldWrapper>
<FieldWrapper>
<FieldTitle>Amount</FieldTitle>
<FieldValue>{(lamports || 0) / web3.LAMPORTS_PER_SOL}</FieldValue>
<FieldValue>{amount}</FieldValue>
{/* <FieldValue>0,00344 BTC at 12 902, 07 US$</FieldValue> */}
</FieldWrapper>
<FieldWrapper>
<FieldTitle>Value</FieldTitle>
<FieldValue>{(lamports || 0) / web3.LAMPORTS_PER_SOL}</FieldValue>
<FieldValue>{amount}</FieldValue>
{/* <FieldValue>0,00344 BTC at 12 902, 07 US$</FieldValue> */}
</FieldWrapper>
{transaction.meta ? (
<FieldWrapper>
<FieldTitle>Fee</FieldTitle>
<FieldValue>{transaction.meta.fee}</FieldValue>
<FieldValue>{transaction.meta.fee} SOL</FieldValue>
{/* <FieldValue>0,00009492 BTC</FieldValue> */}
</FieldWrapper>
) : null}
Expand Down
45 changes: 39 additions & 6 deletions src/components/pages/send/ResultWidget/ResultWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import { Button, Icon } from 'components/ui';
import { openModal } from 'store/actions/modals';
import { getConfirmedTransaction } from 'store/actions/solana';
import { SHOW_MODAL_TRANSACTION_DETAILS } from 'store/constants/modalTypes';
import { RootState } from 'store/types';
import { RootState, TokenAccount } from 'store/types';
import { useDecodeSystemProgramInstructions } from 'utils/hooks/instructions/useDecodeSystemProgramInstructions';
import { useDecodeTokenRegInstructions } from 'utils/hooks/instructions/useDecodeTokenRegInstractions';
import { usePopulateTokenInfo } from 'utils/hooks/usePopulateTokenInfo';

const WrapperCard = styled(Card)`
display: flex;
Expand Down Expand Up @@ -50,6 +52,13 @@ const ArrowIcon = styled(Icon)`
transform: rotate(180deg);
`;

const InfoWrapper = styled.div`
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 32px;
`;

const Value = styled.div`
color: #000000;
font-weight: 500;
Expand All @@ -74,8 +83,6 @@ const Status = styled.div`
`;

const Details = styled.div`
margin-bottom: 32px;
color: ${rgba('#000', 0.5)};
font-size: 14px;
line-height: 140%;
Expand All @@ -94,10 +101,19 @@ export const ResultWidget: FunctionComponent<Props> = (props) => {
(state: RootState) => state.entities.transactionsNormalized[signature],
);

const transactionAuthor = transaction?.transaction.signatures[0].publicKey.toBase58();
const tokenAccount: TokenAccount = useSelector(
(state: RootState) => state.entities.tokens.items[transactionAuthor],
);
const { mint } = tokenAccount?.parsed || { amount: 0 };
let { symbol } = usePopulateTokenInfo({ mint: mint?.toBase58() });

const { type, fromPubkey, lamports, toPubkey } = useDecodeSystemProgramInstructions(
transaction?.transaction.instructions,
);

const { transfer } = useDecodeTokenRegInstructions(transaction?.transaction.instructions);

useEffect(() => {
dispatch(getConfirmedTransaction(signature));
}, []);
Expand All @@ -106,15 +122,32 @@ export const ResultWidget: FunctionComponent<Props> = (props) => {
dispatch(openModal(SHOW_MODAL_TRANSACTION_DETAILS, { signature }));
};

// TODO: dirty
let amount = 0;
if (type) {
symbol = 'SOL';
amount = (lamports || 0) / web3.LAMPORTS_PER_SOL;
} else if (transfer) {
amount = (transfer.amount || 0) / web3.LAMPORTS_PER_SOL;
}

return (
<WrapperCard>
<HeaderImage />
<CircleWrapper>
<ArrowIcon name="arrow-angle" />
</CircleWrapper>
<Value>{lamports / web3.LAMPORTS_PER_SOL}</Value>
<Status>Processed</Status>
<Details onClick={handleDetailsClick}>Transaction details</Details>
<InfoWrapper>
{transaction ? (
<Value>
{amount} {symbol}
</Value>
) : undefined}
<Status>{transaction ? 'Processed' : 'Processing'}</Status>
{transaction ? (
<Details onClick={handleDetailsClick}>Transaction details</Details>
) : undefined}
</InfoWrapper>
<Button primary big full as={Link} to={`/wallet/${fromPubkey}`}>
Go back to wallet
</Button>
Expand Down

0 comments on commit 282d19e

Please sign in to comment.