Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`<Asset /> renders correctly and matches snapshot 1`] = `
<div
className="flex flex-col w-full border border-[#3C3C53] rounded-xl px-6 py-4 mb-4 mt-8 cursor-pointer mt-0"
data-testid="deposit-asset"
id="deposit-app-token-asset"
onClick={[MockFunction]}
>
<div
Expand Down
67 changes: 43 additions & 24 deletions src/apps/deposit/components/AssetsList/AssetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
getNetworkViem,
getNftBalance,
} from '../../utils/blockchain';
import BaseList from '../../utils/tokens/base-tokens.json';
import EthereumList from '../../utils/tokens/ethereum-tokens.json';
import GnosisList from '../../utils/tokens/gnosis-tokens.json';
import PolygonList from '../../utils/tokens/polygon-tokens.json';
Expand All @@ -38,6 +39,7 @@ const tokenLists = {
1: EthereumList,
137: PolygonList,
100: GnosisList,
8453: BaseList,
};

type AssetsListProps = {
Expand All @@ -58,12 +60,9 @@ const AssetsList = ({ accountAddress, chainId }: AssetsListProps) => {
const dispatch = useAppDispatch();
const [addedAssets, setAddedAssets] = useState<AddedAssets[]>(() => {
const storedAssets = localStorage.getItem('addedAssets');
return storedAssets
? JSON.parse(storedAssets).filter(
(token: AddedAssets) => token.balance > 0
)
: [];
return storedAssets ? JSON.parse(storedAssets) : [];
});

const [activeTab, setActiveTab] = useState<'tokens' | 'nfts'>('tokens');

const chainName = getNetworkViem(chainId).name.toLowerCase();
Expand Down Expand Up @@ -260,9 +259,7 @@ const AssetsList = ({ accountAddress, chainId }: AssetsListProps) => {
return;
}

const updatedAssets = [...addedAssets, asset].filter(
(token) => token.balance > 0
);
const updatedAssets = [...addedAssets, asset];
setAddedAssets(updatedAssets);
localStorage.setItem('addedAssets', JSON.stringify(updatedAssets));
};
Expand Down Expand Up @@ -292,17 +289,27 @@ const AssetsList = ({ accountAddress, chainId }: AssetsListProps) => {
balance: Number(readableBalance),
assetType: 'token',
});

setMessage(
`New asset ${newAsset.tokenAddress} on ${chainName} successfully added`
);
setTimeout(() => {
setMessage(null);
}, 5000);
setNewAsset({ tokenAddress: '', chain: '', tokenId: '' });
setIsAddingAsset(false);
}

if (Number(readableBalance) === 0) {
setMessage(
`New asset ${newAsset.tokenAddress} on ${chainName} has not been added because there is no balance in your wallet.`
);
setTimeout(() => {
setMessage(null);
}, 5000);
setNewAsset({ tokenAddress: '', chain: '', tokenId: '' });
setIsAddingAsset(false);
}
setMessage(
`New asset ${newAsset.tokenAddress} on ${(
<span className="capitalize">{chainName}</span>
)} successfully added`
);
setTimeout(() => {
setMessage(null);
}, 5000);
setNewAsset({ tokenAddress: '', chain: '', tokenId: '' });
setIsAddingAsset(false);
}

if (
Expand All @@ -324,13 +331,25 @@ const AssetsList = ({ accountAddress, chainId }: AssetsListProps) => {
assetType: 'nft',
tokenId: newAsset.tokenId,
});

setMessage(`New asset ${newAsset.tokenAddress} successfully added`);
setTimeout(() => {
setMessage(null);
}, 5000);
setNewAsset({ tokenAddress: '', chain: '', tokenId: '' });
setIsAddingAsset(false);
}

if (newAssetBalance === 0) {
setMessage(
`New asset ${newAsset.tokenAddress} has not been added because there is no balance in your wallet.`
);
setTimeout(() => {
setMessage(null);
}, 5000);
setNewAsset({ tokenAddress: '', chain: '', tokenId: '' });
setIsAddingAsset(false);
}
setMessage(`New asset ${newAsset.tokenAddress} successfully added`);
setTimeout(() => {
setMessage(null);
}, 5000);
setNewAsset({ tokenAddress: '', chain: '', tokenId: '' });
setIsAddingAsset(false);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`<AssetsList /> renders correctly and matches snapshot 1`] = `
<div
className="flex flex-col gap-4 w-full mt-8"
id="deposit-app-assets-list"
>
<p
className="text-sm text-left"
Expand Down
8 changes: 6 additions & 2 deletions src/apps/deposit/components/SendAsset/SendAsset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ const SendAsset = () => {
);

setMessage(
`The transaction has succesfully been sent to your external wallet with the transaction hash: ${txHash}. Please check your external wallet to follow the transaction status.`
txHash.length
? `The transaction has succesfully been sent to your external wallet with the transaction hash: ${txHash}. Please check your external wallet to follow the transaction status.`
: 'The transaction has not been succesful. Please check your external wallet to check the transaction status.'
);

setTimeout(() => {
Expand Down Expand Up @@ -89,7 +91,9 @@ const SendAsset = () => {
);

setMessage(
`The transaction has succesfully been sent to your external wallet with the transaction hash: ${txHash}. Please check your external wallet to follow the transaction status.`
txHash.length
? `The transaction has succesfully been sent to your external wallet with the transaction hash: ${txHash}. Please check your external wallet to follow the transaction status.`
: 'The transaction has not been succesful. Please check your external wallet to check the transaction status.'
);

setTimeout(() => {
Expand Down
34 changes: 30 additions & 4 deletions src/apps/deposit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,31 @@ import {
createAppKit,
useAppKit,
useAppKitAccount,
useAppKitEvents,
useAppKitNetworkCore,
useDisconnect,
} from '@reown/appkit/react';
import { useEffect } from 'react';

// styles
import styled from 'styled-components';
import './styles/tailwindDeposit.css';

// utils
import { getNetworkViem } from './utils/blockchain';

// reducer
import { setDepositStep } from './reducer/depositSlice';

// hooks
import { useAppDispatch, useAppSelector } from './hooks/useReducerHooks';

// components
import AssetsList from './components/AssetsList/AssetsList';
import SendAsset from './components/SendAsset/SendAsset';
import { useAppSelector } from './hooks/useReducerHooks';

// images
import PillarXLogo from './images/logo512.png';
import './styles/tailwindDeposit.css';
import { getNetworkViem } from './utils/blockchain';

const metadataReownAppKit = {
name: 'PillarX',
Expand All @@ -32,6 +47,9 @@ createAppKit({
swaps: false,
onramp: false,
history: false,
email: false,
socials: false,
emailShowWallets: false,
},
});

Expand All @@ -40,10 +58,18 @@ const App = () => {
const { address, isConnected } = useAppKitAccount();
const { disconnect } = useDisconnect();
const { chainId } = useAppKitNetworkCore();
const events = useAppKitEvents();
const dispatch = useAppDispatch();
const depositStep = useAppSelector(
(state) => state.deposit.depositStep as 'list' | 'send'
);

useEffect(() => {
if (events.data.event === 'SWITCH_NETWORK') {
dispatch(setDepositStep('list'));
}
}, [events, dispatch]);

const handleDisconnect = async () => {
await disconnect();
};
Expand Down Expand Up @@ -107,7 +133,7 @@ const Wrapper = styled.div`
display: flex;
width: 100%;
min-height: 100vh;
margin: 0 auto;
margin: 0 auto 60px auto;
flex-direction: column;

@media (min-width: 768px) {
Expand Down
Loading