Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: revamp stacks nfts send to screen #653

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
npx lint-staged --no-stash
4 changes: 1 addition & 3 deletions src/app/components/recipientAddressView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ArrowSquareOut from '@assets/img/arrow_square_out.svg';
import { useBnsName } from '@hooks/queries/useBnsName';
import useNetworkSelector from '@hooks/useNetwork';
import { getExplorerUrl } from '@utils/helper';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';
Expand Down Expand Up @@ -56,9 +55,8 @@ interface Props {
recipient: string;
}
function RecipientAddressView({ recipient }: Props) {
const selectedNetwork = useNetworkSelector();
const { t } = useTranslation('translation', { keyPrefix: 'CONFIRM_TRANSACTION' });
const bnsName = useBnsName(recipient, selectedNetwork);
const bnsName = useBnsName(recipient);
const handleOnPress = () => {
window.open(getExplorerUrl(recipient));
};
Expand Down
45 changes: 23 additions & 22 deletions src/app/components/sendForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import ActionButton from '@components/button';
import InfoContainer from '@components/infoContainer';
import TokenImage from '@components/tokenImage';
import { useBnsName, useBNSResolver } from '@hooks/queries/useBnsName';
import { useBnsName, useBnsResolver } from '@hooks/queries/useBnsName';
import useDebounce from '@hooks/useDebounce';
import useNetworkSelector from '@hooks/useNetwork';
import useWalletSelector from '@hooks/useWalletSelector';
import { getBtcEquivalent, getStxTokenEquivalent } from '@secretkeylabs/xverse-core';
import { getFiatEquivalent } from '@secretkeylabs/xverse-core/transactions';
import { FungibleToken } from '@secretkeylabs/xverse-core/types';
import {
FungibleToken,
getBtcEquivalent,
getFiatEquivalent,
getStxTokenEquivalent,
} from '@secretkeylabs/xverse-core';
import InputFeedback from '@ui-library/inputFeedback';
import { CurrencyTypes } from '@utils/constants';
import { getCurrencyFlag } from '@utils/currency';
Expand Down Expand Up @@ -64,45 +66,45 @@ const MemoContainer = styled.div((props) => ({
marginBottom: props.theme.spacing(6),
}));

const ErrorText = styled.h1((props) => ({
...props.theme.body_xs,
color: props.theme.colors.feedback.error,
const ErrorText = styled.p((props) => ({
...props.theme.typography.body_s,
color: props.theme.colors.danger_medium,
}));

const InputFieldContainer = styled.div(() => ({
flex: 1,
}));

const TitleText = styled.h1((props) => ({
...props.theme.body_medium_m,
const TitleText = styled.p((props) => ({
...props.theme.typography.body_medium_m,
flex: 1,
display: 'flex',
}));

const Text = styled.h1((props) => ({
...props.theme.body_medium_m,
const Text = styled.p((props) => ({
...props.theme.typography.body_medium_m,
}));

const SubText = styled.h1((props) => ({
...props.theme.body_xs,
const SubText = styled.p((props) => ({
...props.theme.typography.body_s,
display: 'flex',
flex: 1,
color: props.theme.colors.white_400,
}));

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

const BalanceText = styled.h1((props) => ({
...props.theme.body_medium_m,
const BalanceText = styled.p((props) => ({
...props.theme.typography.body_medium_m,
color: props.theme.colors.white_400,
marginRight: props.theme.spacing(2),
}));

const InputField = styled.input((props) => ({
...props.theme.body_m,
...props.theme.typography.body_m,
backgroundColor: props.theme.colors.elevation_n1,
color: props.theme.colors.white_0,
width: '100%',
Expand Down Expand Up @@ -224,10 +226,9 @@ function SendForm({

const { stxBtcRate, btcFiatRate, fiatCurrency, stxAddress, selectedAccount } =
useWalletSelector();
const network = useNetworkSelector();
const debouncedSearchTerm = useDebounce(recipientAddress, 300);
const associatedBnsName = useBnsName(recipientAddress, network);
const associatedAddress = useBNSResolver(debouncedSearchTerm, stxAddress, currencyType);
const associatedBnsName = useBnsName(recipientAddress);
const associatedAddress = useBnsResolver(debouncedSearchTerm, stxAddress, currencyType);
const { isAccountSwitched } = useClearFormOnAccountSwitch();

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/tabBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Button = styled.button({
zIndex: 2,
});

type Tab = 'dashboard' | 'nft' | 'stacking' | 'settings';
export type Tab = 'dashboard' | 'nft' | 'stacking' | 'settings';

interface Props {
tab: Tab;
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/tokenTile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ function TokenTile({
onPress({
coin: currency as CurrencyTypes,
ft: fungibleToken && fungibleToken.principal,
brc20Ft: !fungibleToken?.principal && fungibleToken?.name,
brc20Ft: !fungibleToken?.principal ? fungibleToken?.name : undefined,
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/components/topRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const AnimatedBackButton = styled(BackButton)`

interface Props {
title: string;
onClick: () => void;
onClick: (e: React.MouseEvent<HTMLButtonElement>) => void;
showBackButton?: boolean;
className?: string;
}
Expand Down
16 changes: 8 additions & 8 deletions src/app/hooks/queries/useBnsName.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { fetchAddressOfBnsName, getBnsName, validateStxAddress } from '@secretkeylabs/xverse-core';
import { useEffect, useState } from 'react';
import { StacksNetwork, validateStxAddress } from '@secretkeylabs/xverse-core';
import { fetchAddressOfBnsName, getBnsName } from '@secretkeylabs/xverse-core/api';
import useWalletSelector from '../useWalletSelector';
import useNetworkSelector from '../useNetwork';
import useWalletSelector from '../useWalletSelector';

export const useBnsName = (walletAddress: string, network: StacksNetwork) => {
export const useBnsName = (walletAddress: string) => {
const network = useNetworkSelector();
const [bnsName, setBnsName] = useState('');

useEffect(() => {
(async () => {
const name = await getBnsName(walletAddress, network);
setBnsName(name ?? '');
})();
}, [walletAddress]);
}, [walletAddress, network]);

return bnsName;
};

export const useBNSResolver = (
export const useBnsResolver = (
recipientAddress: string,
walletAddress: string,
currencyType: string,
currencyType?: string,
) => {
const { network } = useWalletSelector();
const selectedNetwork = useNetworkSelector();
Expand All @@ -43,7 +43,7 @@ export const useBNSResolver = (
setAssociatedAddress('');
}
})();
}, [recipientAddress]);
}, [recipientAddress, network, currencyType, selectedNetwork, walletAddress]);
fedeerbes marked this conversation as resolved.
Show resolved Hide resolved

return associatedAddress;
};
101 changes: 101 additions & 0 deletions src/app/layouts/sendLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import AccountHeaderComponent from '@components/accountHeader';
import BottomBar, { Tab } from '@components/tabBar';
import TopRow from '@components/topRow';
import { ArrowLeft } from '@phosphor-icons/react';
import { StyledP } from '@ui-library/common.styled';
import { PropsWithChildren } from 'react';
import { useTranslation } from 'react-i18next';
import styled from 'styled-components';
import { breakpoints, devices } from 'theme';

const ScrollContainer = styled.div((props) => ({
display: 'flex',
flex: 1,
flexDirection: 'column',
...props.theme.scrollbar,
}));

const Container = styled.div`
display: flex;
flex-direction: column;
margin: auto;
margin-top: ${(props) => props.theme.space.xxs};
padding: 0 ${(props) => props.theme.space.s};
width: 100%;
height: 100%;
max-width: ${breakpoints.xs}px;
max-height: 600px;

@media only screen and ${devices.min.s} {
flex: initial;
max-width: 588px;
border: 1px solid ${(props) => props.theme.colors.elevation3};
border-radius: ${(props) => props.theme.space.s};
padding: ${(props) => props.theme.space.l} ${(props) => props.theme.space.m};
padding-bottom: ${(props) => props.theme.space.xxl};
margin-top: ${(props) => props.theme.space.xxxxl};
}
`;

const FooterContainer = styled.div`
display: flex;
justify-content: center;
margin-bottom: ${(props) => props.theme.space.xxl};
`;

const BottomBarContainer = styled.div({
marginTop: 'auto',
});

const Button = styled.button`
display: flex;
background-color: transparent;
margin-bottom: ${(props) => props.theme.space.l};
`;

function SendLayout({
children,
selectedBottomTab,
onClickBack,
hideBackButton = false,
}: PropsWithChildren<{
selectedBottomTab: Tab;
onClickBack?: (e: React.MouseEvent<HTMLButtonElement>) => void;
hideBackButton?: boolean;
}>) {
const { t } = useTranslation('translation', { keyPrefix: 'SEND' });
const isScreenLargerThanXs = document.documentElement.clientWidth > Number(breakpoints.xs);
const year = new Date().getFullYear();

return (
<>
{isScreenLargerThanXs ? (
<AccountHeaderComponent disableMenuOption={isScreenLargerThanXs} disableAccountSwitch />
) : (
<TopRow title="" onClick={onClickBack!} showBackButton={!hideBackButton && !!onClickBack} />
)}
<ScrollContainer>
<Container>
{isScreenLargerThanXs && !hideBackButton && onClickBack && (
<Button onClick={onClickBack}>
<ArrowLeft size={20} color="white" />
</Button>
)}
{children}
</Container>
{isScreenLargerThanXs && (
Copy link
Contributor

@fedeerbes fedeerbes Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be cool to have a component which handles rendering according to break points, cause i see a lot of this conditional renders with the variable defined above. something like

<RenderBPLayout
    xs={<Component/>}
    m={ <Component/>}
    />

or

<RenderBPLayout
    >
      {(breakpoint) => {
        switch (breakpoint) {
          case 'xs':
            return <Component/>;
          case 'm':
            return <Component/>;
          default:
            return <Component/>;
      }
      }
    </RenderBPLayout>

<FooterContainer>
<StyledP typography="body_medium_m" color="white_400">
{t('COPYRIGHT', { year })}
</StyledP>
</FooterContainer>
)}
</ScrollContainer>
<BottomBarContainer>
{!isScreenLargerThanXs && <BottomBar tab={selectedBottomTab} />}
</BottomBarContainer>
</>
);
}

export default SendLayout;
4 changes: 0 additions & 4 deletions src/app/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,6 @@ const router = createHashRouter([
</AuthGuard>
),
},
{
path: 'send-nft/:id',
element: <SendNft />,
},
{
path: 'confirm-inscription-request',
element: (
Expand Down
4 changes: 2 additions & 2 deletions src/app/screens/coinDashboard/coinHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import useWalletSelector from '@hooks/useWalletSelector';
import { FungibleToken, microstacksToStx, satsToBtc } from '@secretkeylabs/xverse-core';
import { currencySymbolMap } from '@secretkeylabs/xverse-core/types/currency';
import { CurrencyTypes } from '@utils/constants';
import { isLedgerAccount } from '@utils/helper';
import { isInOptions, isLedgerAccount } from '@utils/helper';
import { getFtBalance, getFtTicker } from '@utils/tokens';
import BigNumber from 'bignumber.js';
import { useState } from 'react';
Expand Down Expand Up @@ -262,7 +262,7 @@ export default function CoinHeader(props: CoinBalanceProps) {
};

const goToSendScreen = async () => {
if (isLedgerAccount(selectedAccount)) {
if (isLedgerAccount(selectedAccount) && !isInOptions()) {
switch (coin) {
case 'BTC':
await chrome.tabs.create({
Expand Down
30 changes: 19 additions & 11 deletions src/app/screens/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import CoinSelectModal from '@screens/home/coinSelectModal';
import type { FungibleToken } from '@secretkeylabs/xverse-core';
import { changeShowDataCollectionAlertAction } from '@stores/wallet/actions/actionCreators';
import { CurrencyTypes } from '@utils/constants';
import { isLedgerAccount } from '@utils/helper';
import { isInOptions, isLedgerAccount } from '@utils/helper';
import { optInMixPanel, optOutMixPanel } from '@utils/mixpanel';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -250,7 +250,7 @@ function Home() {
};

const onStxSendClick = async () => {
if (isLedgerAccount(selectedAccount)) {
if (isLedgerAccount(selectedAccount) && !isInOptions()) {
await chrome.tabs.create({
url: chrome.runtime.getURL('options.html#/send-stx'),
});
Expand All @@ -260,7 +260,7 @@ function Home() {
};

const onBtcSendClick = async () => {
if (isLedgerAccount(selectedAccount)) {
if (isLedgerAccount(selectedAccount) && !isInOptions()) {
await chrome.tabs.create({
url: chrome.runtime.getURL('options.html#/send-btc'),
});
Expand All @@ -280,10 +280,14 @@ function Home() {
const onSendFtSelect = async (coin: FungibleToken) => {
if (coin.protocol === 'brc-20') {
if (isLedgerAccount(selectedAccount)) {
await chrome.tabs.create({
// TODO replace with send-brc20-one-step route, when ledger support is ready
url: chrome.runtime.getURL(`options.html#/send-brc20?coinName=${coin.name}`),
});
if (!isInOptions()) {
await chrome.tabs.create({
// TODO replace with send-brc20-one-step route, when ledger support is ready
url: chrome.runtime.getURL(`options.html#/send-brc20?coinName=${coin.name}`),
});
return;
}
navigate(`send-brc20?coinName=${coin.name}`);
return;
}
navigate('send-brc20-one-step', {
Expand All @@ -293,7 +297,7 @@ function Home() {
});
return;
}
if (isLedgerAccount(selectedAccount)) {
if (isLedgerAccount(selectedAccount) && !isInOptions()) {
await chrome.tabs.create({
url: chrome.runtime.getURL(`options.html#/send-ft?coinTicker=${coin.ticker}`),
});
Expand Down Expand Up @@ -392,9 +396,13 @@ function Home() {
icon={<Plus color="white" size={20} />}
text={t('ADD_STACKS_ADDRESS')}
onPress={async () => {
await chrome.tabs.create({
url: chrome.runtime.getURL(`options.html#/add-stx-address-ledger`),
});
if (!isInOptions()) {
await chrome.tabs.create({
url: chrome.runtime.getURL(`options.html#/add-stx-address-ledger`),
});
} else {
navigate('/add-stx-address-ledger');
}
}}
/>
)}
Expand Down
Loading