From dd9fb2546c20b25e663e330cb9148a912ff34587 Mon Sep 17 00:00:00 2001 From: Armani Ferrante Date: Fri, 9 Apr 2021 14:47:55 +0800 Subject: [PATCH] Merge accounts with token transfers (#174) --- src/components/BalancesList.js | 9 +++++++++ src/components/MergeAccountsDialog.js | 14 +++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/components/BalancesList.js b/src/components/BalancesList.js index f5283ca..1370404 100644 --- a/src/components/BalancesList.js +++ b/src/components/BalancesList.js @@ -31,6 +31,7 @@ import IconButton from '@material-ui/core/IconButton'; import InfoIcon from '@material-ui/icons/InfoOutlined'; import Tooltip from '@material-ui/core/Tooltip'; import EditIcon from '@material-ui/icons/Edit'; +import MergeType from '@material-ui/icons/MergeType'; import SortIcon from '@material-ui/icons/Sort'; import AddTokenDialog from './AddTokenDialog'; import ExportAccountDialog from './ExportAccountDialog'; @@ -209,6 +210,14 @@ export default function BalancesList() { )} + + setShowMergeAccounts(true)} + > + + + associated token accounts {' '} - ,{' '} - deduplicating and closing any accounts that share the same mint. - If associated token accounts do not exist, then they will be - created. + . If + associated token accounts do not exist, then they will be created. If merging fails during a period of high network load, you will @@ -242,10 +241,12 @@ export default function MergeAccountsDialog({ open, onClose }) { async function mergeMint( assocTokAddr, mintAccountSet, + mint, wallet, connection, enqueueSnackbar, ) { + console.log('mint', mint, mint.toString()); if (mintAccountSet.length === 0) { return; } @@ -286,13 +287,12 @@ async function mergeMint( const tokenAccount = mintAccountSet[k]; if (tokenAccount.publicKey.equals(associatedTokenAccount) === false) { if (tokenAccount.account.amount > 0) { - await wallet.transferAndClose( + await wallet.transferToken( tokenAccount.publicKey, associatedTokenAccount, tokenAccount.account.amount, + mint, ); - } else { - await wallet.closeTokenAccount(tokenAccount.publicKey, true); } } }