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: add arc200 asset #63

Merged
merged 16 commits into from
Dec 22, 2023
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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
"private": true,
"engines": {
"node": ">=15.0.0"
"node": ">=20.9.0"
},
"scripts": {
"analyze:chrome": "yarn build:chrome --analyze",
Expand Down Expand Up @@ -116,7 +116,8 @@
"@walletconnect/core": "^2.8.0",
"@walletconnect/utils": "^2.8.0",
"@walletconnect/web3wallet": "^1.8.0",
"algosdk": "^2.1.0",
"algosdk": "^2.7.0",
"arc200js": "^2.3.1",
"bignumber.js": "^9.1.1",
"buffer": "^6.0.3",
"chakra-ui-steps": "2.0.4",
Expand Down
6 changes: 4 additions & 2 deletions src/extension/apps/background/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import Root from './Root';

// features
import { reducer as accountsReducer } from '@extension/features/accounts';
import { reducer as assetsReducer } from '@extension/features/assets';
import { reducer as arc200AssetsReducer } from '@extension/features/arc200-assets';
import { reducer as eventsReducer } from '@extension/features/events';
import { reducer as messagesReducer } from '@extension/features/messages';
import { reducer as networksReducer } from '@extension/features/networks';
import { reducer as sessionsReducer } from '@extension/features/sessions';
import { reducer as settingsReducer } from '@extension/features/settings';
import { reducer as standardAssetsReducer } from '@extension/features/standard-assets';
import { reducer as systemReducer } from '@extension/features/system';

// types
Expand All @@ -27,12 +28,13 @@ const App: FC<IAppProps> = ({ i18next, initialColorMode }: IAppProps) => {
const store: Store<IBackgroundRootState> = makeStore<IBackgroundRootState>(
combineReducers({
accounts: accountsReducer,
assets: assetsReducer,
arc200Assets: arc200AssetsReducer,
events: eventsReducer,
messages: messagesReducer,
networks: networksReducer,
sessions: sessionsReducer,
settings: settingsReducer,
standardAssets: standardAssetsReducer,
system: systemReducer,
})
);
Expand Down
8 changes: 6 additions & 2 deletions src/extension/apps/main/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ import {

// features
import { reducer as accountsReducer } from '@extension/features/accounts';
import { reducer as assetsReducer } from '@extension/features/assets';
import { reducer as addAssetReducer } from '@extension/features/add-asset';
import { reducer as arc200AssetsReducer } from '@extension/features/arc200-assets';
import { reducer as eventsReducer } from '@extension/features/events';
import { reducer as messagesReducer } from '@extension/features/messages';
import { reducer as networksReducer } from '@extension/features/networks';
import { reducer as notificationsReducer } from '@extension/features/notifications';
import { reducer as sendAssetsReducer } from '@extension/features/send-assets';
import { reducer as sessionsReducer } from '@extension/features/sessions';
import { reducer as settingsReducer } from '@extension/features/settings';
import { reducer as standardAssetsReducer } from '@extension/features/standard-assets';
import {
reducer as systemReducer,
setSideBar,
Expand Down Expand Up @@ -86,14 +88,16 @@ const App: FC<IAppProps> = ({ i18next, initialColorMode }: IAppProps) => {
const store: Store<IMainRootState> = makeStore<IMainRootState>(
combineReducers({
accounts: accountsReducer,
assets: assetsReducer,
addAsset: addAssetReducer,
arc200Assets: arc200AssetsReducer,
events: eventsReducer,
messages: messagesReducer,
networks: networksReducer,
notifications: notificationsReducer,
sendAssets: sendAssetsReducer,
sessions: sessionsReducer,
settings: settingsReducer,
standardAssets: standardAssetsReducer,
system: systemReducer,
})
);
Expand Down
64 changes: 12 additions & 52 deletions src/extension/apps/main/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useDispatch } from 'react-redux';
import { NavigateFunction, Outlet, useNavigate } from 'react-router-dom';

// components
import AddAssetModal from '@extension/components/AddAssetModal';
import ConfirmModal from '@extension/components/ConfirmModal';
import EnableModal from '@extension/components/EnableModal';
import ErrorModal from '@extension/components/ErrorModal';
Expand All @@ -13,14 +14,12 @@ import SignTxnsModal from '@extension/components/SignTxnsModal';
import WalletConnectModal from '@extension/components/WalletConnectModal';

// features
import { reset as resetAddAsset } from '@extension/features/add-asset';
import {
fetchAccountsFromStorageThunk,
startPollingForAccountsThunk,
} from '@extension/features/accounts';
import {
fetchAssetsThunk,
updateAssetInformationThunk,
} from '@extension/features/assets';
import { fetchArc200AssetsFromStorageThunk } from '@extension/features/arc200-assets';
import {
setEnableRequest,
setSignBytesRequest,
Expand All @@ -37,41 +36,32 @@ import {
initializeWalletConnectThunk,
} from '@extension/features/sessions';
import { fetchSettings } from '@extension/features/settings';
import { fetchStandardAssetsFromStorageThunk } from '@extension/features/standard-assets';
import { setConfirm, setError, setNavigate } from '@extension/features/system';

// hooks
import useOnMainAppMessage from '@extension/hooks/useOnMainAppMessage';
import useOnNetworkConnectivity from '@extension/hooks/useOnNetworkConnectivity';
import useOnNewAssets from '@extension/hooks/useOnNewAssets';
import useNotifications from '@extension/hooks/useNotifications';

// selectors
import {
useSelectAccounts,
useSelectAssets,
useSelectSelectedNetwork,
} from '@extension/selectors';

// types
import {
IAccount,
IAccountInformation,
IAppThunkDispatch,
IAsset,
IAssetHolding,
INetwork,
} from '@extension/types';

// utils
import { convertGenesisHashToHex } from '@extension/utils';
import { IAccount, IAppThunkDispatch, INetwork } from '@extension/types';

const Root: FC = () => {
const dispatch: IAppThunkDispatch = useDispatch<IAppThunkDispatch>();
const navigate: NavigateFunction = useNavigate();
// hooks
// selectors
const accounts: IAccount[] = useSelectAccounts();
const assets: Record<string, IAsset[]> | null = useSelectAssets();
const selectedNetwork: INetwork | null = useSelectSelectedNetwork();
// handlers
const handleAddAssetClose = () => dispatch(resetAddAsset());
const handleConfirmClose = () => dispatch(setConfirm(null));
const handleEnableModalClose = () => dispatch(setEnableRequest(null));
const handleErrorModalClose = () => dispatch(setError(null));
Expand All @@ -86,7 +76,8 @@ const Root: FC = () => {
dispatch(setNavigate(navigate));
dispatch(fetchSettings());
dispatch(fetchSessionsThunk());
dispatch(fetchAssetsThunk());
dispatch(fetchStandardAssetsFromStorageThunk());
dispatch(fetchArc200AssetsFromStorageThunk());
dispatch(initializeWalletConnectThunk());
dispatch(startPollingForAccountsThunk());
dispatch(startPollingForTransactionsParamsThunk());
Expand All @@ -108,39 +99,7 @@ const Root: FC = () => {
dispatch(fetchTransactionParamsFromStorageThunk());
}
}, [selectedNetwork]);
// whenever the accounts are updated, check if any new assets exist in the account
useEffect(() => {
if (accounts.length > 0 && assets && selectedNetwork) {
accounts.forEach((account) => {
const encodedGenesisHash: string = convertGenesisHashToHex(
selectedNetwork.genesisHash
).toUpperCase();
const accountInformation: IAccountInformation | null =
account.networkInformation[encodedGenesisHash] || null;
let newAssets: IAssetHolding[];

if (accountInformation) {
// filter out any new assets
newAssets = accountInformation.assetHoldings.filter(
(assetHolding) =>
!assets[encodedGenesisHash].some(
(value) => value.id === assetHolding.id
)
);

// if we have any new assets, update the information
if (newAssets.length > 0) {
dispatch(
updateAssetInformationThunk({
ids: newAssets.map((value) => value.id),
network: selectedNetwork,
})
);
}
}
});
}
}, [accounts]);
useOnNewAssets(); // handle new assets added
useNotifications(); // handle notifications
useOnNetworkConnectivity(); // listen to network connectivity
useOnMainAppMessage(); // handle incoming messages
Expand All @@ -152,6 +111,7 @@ const Root: FC = () => {
<EnableModal onClose={handleEnableModalClose} />
<SignTxnsModal onClose={handleSignTxnsModalClose} />
<SignBytesModal onClose={handleSignBytesModalClose} />
<AddAssetModal onClose={handleAddAssetClose} />
<SendAssetModal onClose={handleSendAssetModalClose} />
<WalletConnectModal onClose={handleWalletConnectModalClose} />
<MainLayout>
Expand Down
Loading
Loading