Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-extension into imamahzafar/feat/stacking
  • Loading branch information
Imamah-Zafar committed Nov 21, 2022
2 parents 42c3cac + a051132 commit eab617d
Show file tree
Hide file tree
Showing 28 changed files with 1,155 additions and 83 deletions.
30 changes: 30 additions & 0 deletions package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ const Container = styled.div`
const ButtonContainer = styled.div((props) => ({
display: 'flex',
flexDirection: 'row',
marginLeft: props.theme.spacing(8),
marginRight: props.theme.spacing(8),
marginBottom: props.theme.spacing(8),
marginBottom: props.theme.spacing(20),
marginTop: props.theme.spacing(24),
}));

const TransparentButtonContainer = styled.div((props) => ({
Expand All @@ -49,12 +48,10 @@ const TransparentButtonContainer = styled.div((props) => ({
const Button = styled.button((props) => ({
display: 'flex',
flexDirection: 'row',
justifyContent: 'flex-end',
alignItems: 'center',
borderRadius: props.theme.radius(1),
backgroundColor: 'transparent',
width: '100%',
marginTop: props.theme.spacing(5),
marginTop: props.theme.spacing(10),
}));

const ButtonText = styled.div((props) => ({
Expand All @@ -76,6 +73,7 @@ interface Props {
onConfirmClick: (transactions: StacksTransaction[]) => void;
children: ReactNode;
isSponsored?: boolean;
isNft?: boolean;
}

function ConfirmStxTransationComponent({
Expand All @@ -85,6 +83,7 @@ function ConfirmStxTransationComponent({
children,
onConfirmClick,
onCancelClick,
isNft,
}: Props) {
const { t } = useTranslation('translation', { keyPrefix: 'CONFIRM_TRANSACTION' });
const {
Expand All @@ -98,7 +97,7 @@ function ConfirmStxTransationComponent({
const [buttonLoading, setButtonLoading] = useState(loading);

const handleBackButtonClick = () => {
navigate('/send-stx');
navigate(-1);
};

useEffect(() => {
Expand Down Expand Up @@ -167,7 +166,7 @@ function ConfirmStxTransationComponent({
<>
<TopRow title={t('SEND')} onClick={handleBackButtonClick} />
<Container>
<TransferAmountView currency="STX" amount={getAmount()} />
{!isNft && <TransferAmountView currency="STX" amount={getAmount()} />}
{children}
<TransferFeeView
fee={microstacksToStx(getFee())}
Expand All @@ -189,24 +188,25 @@ function ConfirmStxTransationComponent({
onApplyClick={applyTxSettings}
onCrossClick={closeTransactionSettingAlert}
/>
</Container>
<ButtonContainer>
<TransparentButtonContainer>
<ButtonContainer>
<TransparentButtonContainer>
<ActionButton
text={t('CANCEL')}
transparent
disabled={buttonLoading}
onPress={onCancelClick}
/>
</TransparentButtonContainer>

<ActionButton
text={t('CANCEL')}
transparent
text={t('CONFIRM')}
disabled={buttonLoading}
onPress={onCancelClick}
processing={buttonLoading}
onPress={onConfirmButtonClick}
/>
</TransparentButtonContainer>
</ButtonContainer>
</Container>

<ActionButton
text={t('CONFIRM')}
disabled={buttonLoading}
processing={buttonLoading}
onPress={onConfirmButtonClick}
/>
</ButtonContainer>
</>
);
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/components/recipinetAddressView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useTranslation } from 'react-i18next';
import styled from 'styled-components';
import ArrowSquareOut from '@assets/img/arrow_square_out.svg';
import { getExplorerUrl } from '@utils/helper';
import { useBnsName } from '@hooks/useBnsName';
import useWalletSelector from '@hooks/useWalletSelector';

const InfoContainer = styled.div((props) => ({
display: 'flex',
Expand Down Expand Up @@ -47,15 +49,17 @@ interface Props {
recipient: string;
}
function RecipientAddressView({ recipient }: Props) {
const { network } = useWalletSelector();
const { t } = useTranslation('translation', { keyPrefix: 'CONFIRM_TRANSACTION' });

const bnsName = useBnsName(recipient, network);
const handleOnPress = () => {
window.open(getExplorerUrl(recipient));
};

return (
<InfoContainer>
<TitleText>{t('RECEPIENT_ADDRESS')}</TitleText>
<ValueText>{bnsName}</ValueText>
<RowContainer>
<ValueText>{recipient}</ValueText>
<ActionButton onClick={handleOnPress}>
Expand Down
61 changes: 47 additions & 14 deletions src/app/components/sendForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { CurrencyTypes } from '@utils/constants';
import { FungibleToken } from '@secretkeylabs/xverse-core/types';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';
import { SetStateAction, useState } from 'react';
import {
ReactNode, SetStateAction, useEffect, useState,
} from 'react';
import BigNumber from 'bignumber.js';
import IconBitcoin from '@assets/img/send/ic_sats_ticker.svg';
import IconStacks from '@assets/img/dashboard/stack_icon.svg';
Expand All @@ -14,6 +16,7 @@ import ActionButton from '@components/button';
import {
btcToSats, getBtcFiatEquivalent, getStxFiatEquivalent, stxToMicrostacks,
} from '@secretkeylabs/xverse-core/currency';
import { useBNSResolver, useDebounce } from '@hooks/useBnsName';

const ScrollContainer = styled.div`
display: flex;
Expand All @@ -23,6 +26,8 @@ const ScrollContainer = styled.div`
&::-webkit-scrollbar {
display: none;
}
margin-left: 5%;
margin-right: 5%;
`;
const OuterContainer = styled.div({
display: 'flex',
Expand All @@ -39,8 +44,6 @@ const RowContainer = styled.div({
const InfoContainer = styled.div((props) => ({
display: 'flex',
flexDirection: 'row',
marginLeft: props.theme.spacing(8),
marginRight: props.theme.spacing(8),
padding: props.theme.spacing(8),
border: `1px solid ${props.theme.colors.background.elevation3}`,
borderRadius: 8,
Expand All @@ -50,14 +53,10 @@ const Container = styled.div((props) => ({
display: 'flex',
flexDirection: 'column',
marginTop: props.theme.spacing(11),
marginLeft: props.theme.spacing(8),
marginRight: props.theme.spacing(8),
}));

const ErrorContainer = styled.div((props) => ({
marginTop: props.theme.spacing(8),
marginLeft: props.theme.spacing(10),
marginRight: props.theme.spacing(10),
}));

const ErrorText = styled.h1((props) => ({
Expand Down Expand Up @@ -94,6 +93,11 @@ const SubText = styled.h1((props) => ({
color: props.theme.colors.white['400'],
}));

const AssociatedText = styled.h1((props) => ({
...props.theme.body_xs,
wordWrap: 'break-word',
}));

const BalanceText = styled.h1((props) => ({
...props.theme.body_medium_m,
color: props.theme.colors.white['400'],
Expand Down Expand Up @@ -131,8 +135,6 @@ const TickerImage = styled.img((props) => ({
}));

const SendButtonContainer = styled.div((props) => ({
paddingLeft: props.theme.spacing(8),
paddingRight: props.theme.spacing(8),
paddingBottom: props.theme.spacing(8),
paddingTop: props.theme.spacing(4),
}));
Expand All @@ -146,6 +148,7 @@ interface Props {
hideMemo?: boolean;
buttonText?: string;
processing?: boolean;
children?: ReactNode;
}

function SendForm({
Expand All @@ -158,16 +161,35 @@ function SendForm({
hideMemo = false,
buttonText,
processing,
children,
}: Props) {
const { t } = useTranslation('translation', { keyPrefix: 'SEND' });
const [amount, setAmount] = useState('');
const [memo, setMemo] = useState('');
const [fiatAmount, setFiatAmount] = useState<string | undefined>('0');
const [showError, setShowError] = useState<string | undefined>(error);
const [recipientAddress, setRecipientAddress] = useState('');

const { stxBtcRate, btcFiatRate, fiatCurrency } = useSelector(
const {
stxBtcRate, btcFiatRate, fiatCurrency, stxAddress,
} = useSelector(
(state: StoreState) => state.walletState,
);
const debouncedSearchTerm = useDebounce(recipientAddress, 300);
const associatedAddress = useBNSResolver(
debouncedSearchTerm,
stxAddress,
currencyType,
);

useEffect(() => {
if (error) {
if (associatedAddress !== '' && error.includes(t('ERRORS.ADDRESS_INVALID'))) {
setShowError('');
} else {
setShowError(error);
}
}
}, [error, associatedAddress]);

function getFiatEquivalent(value: number) {
if ((currencyType === 'FT' && !fungibleToken?.tokenFiatRate) || currencyType === 'NFT') {
Expand Down Expand Up @@ -262,6 +284,10 @@ function SendForm({
);
}

const onAddressInputChange = (e: { target: { value: SetStateAction<string> } }) => {
setRecipientAddress(e.target.value);
};

function renderEnterRecepientSection() {
return (
<Container>
Expand All @@ -270,22 +296,29 @@ function SendForm({
<InputFieldContainer>
<InputField
placeholder={t('RECEPIENT_PLACEHOLDER')}
onChange={(e: { target: { value: SetStateAction<string> } }) => setRecipientAddress(e.target.value)}
onChange={onAddressInputChange}
/>
</InputFieldContainer>
</AmountInputContainer>
{associatedAddress && currencyType !== 'BTC' && (
<>
<SubText>{t('ASSOCIATED_ADDRESS')}</SubText>
<AssociatedText>{associatedAddress}</AssociatedText>
</>
)}
</Container>
);
}

const handleOnPress = () => {
onPressSend(recipientAddress, amount, memo);
onPressSend(associatedAddress !== '' ? associatedAddress : debouncedSearchTerm, amount, memo);
};

return (
<ScrollContainer>
<OuterContainer>
{!disableAmountInput && renderEnterAmountSection()}
{children}
{renderEnterRecepientSection()}
{currencyType !== 'BTC' && currencyType !== 'NFT' && !hideMemo && (
<>
Expand All @@ -311,7 +344,7 @@ function SendForm({
)}
</OuterContainer>
<ErrorContainer>
<ErrorText>{error}</ErrorText>
<ErrorText>{showError}</ErrorText>
</ErrorContainer>

<SendButtonContainer>
Expand Down
3 changes: 0 additions & 3 deletions src/app/components/shareNft/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import ShareLinkRow from './shareLinkRow';
const Container = styled.button((props) => ({
display: 'flex',
flexDirection: 'column',
position: 'absolute',
top: 0,
right: 0,
justifyContent: 'center',
paddingLeft: props.theme.spacing(6),
paddingRight: props.theme.spacing(8),
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/topRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const RowContainer = styled.div((props) => ({
flexDirection: 'row',
alignItems: 'center',
paddingTop: props.theme.spacing(11),
paddingLeft: props.theme.spacing(11),
paddingRight: props.theme.spacing(11),
paddingLeft: '5%',
paddingRight: '5%',
}));

interface Props {
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/transferFeeView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import styled from 'styled-components';
const RowContainer = styled.div((props) => ({
display: 'flex',
flexDirection: 'row',
marginTop: props.theme.spacing(6),
marginTop: props.theme.spacing(8),
}));

const FeeText = styled.h1((props) => ({
Expand Down
Loading

0 comments on commit eab617d

Please sign in to comment.