-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet-dashboard): update send flow after clustering coins by co…
…in type (#839) * feat(wallet-dashboard): improve coins portfolio by clustering them by coin type * feat(wallet-dashboard): remove disabled rule * feat(wallet-dashboard): update types and improve code * feat(wallet-dashboard): fix build * feat(wallet-dashboard): remove useCoinMetadata from filterAndSortTokenBalances * feat(wallet-dashboard): cleanup * feat(wallet-dashboard): sort by coinType * feat(wallet-dashboard): add dropdown component * feat(wallet-dashboard): rename component * feat(wallet-dashboard): udpate popup logic * feat(core): add info to function * feat(core): move useSortedCoinsByCategories hook to core and use it in dashboard * feat(wallet-dashboard): add comment and link to issue * feat(wallet-dashboard): cleanup * fix(wallet-dashboard): add conditional and use another format for documentation * fix(dashboard): improvements * feat(dashboard): add disabled feature to dropdown component * fix(dashboard): rename Dropdown fields * feat(wallet-dashboard): allow sending coins with any coin type (#929) * feat(wallet-dashboard): show unrecognized coins * feat(wallet-dashboard): allow sending coins with any coin type --------- Co-authored-by: Begoña Álvarez de la Cruz <[email protected]> Co-authored-by: cpl121 <[email protected]> Co-authored-by: cpl121 <[email protected]>
- Loading branch information
1 parent
c22590d
commit 73507de
Showing
19 changed files
with
237 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export const COINS_QUERY_REFETCH_INTERVAL = 20_000; | ||
export const COINS_QUERY_STALE_TIME = 20_000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { IOTA_FRAMEWORK_ADDRESS, IOTA_SYSTEM_ADDRESS } from '@iota/iota.js/utils'; | ||
|
||
export const DEFAULT_RECOGNIZED_PACKAGES = [IOTA_FRAMEWORK_ADDRESS, IOTA_SYSTEM_ADDRESS]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React from 'react'; | ||
import { useCurrentAccount, useIotaClientQuery } from '@iota/dapp-kit'; | ||
import { CoinItem, SendCoinPopup } from '@/components'; | ||
import { usePopups } from '@/hooks'; | ||
import { CoinBalance } from '@iota/iota.js/client'; | ||
import { | ||
COINS_QUERY_REFETCH_INTERVAL, | ||
COINS_QUERY_STALE_TIME, | ||
filterAndSortTokenBalances, | ||
useSortedCoinsByCategories, | ||
} from '@iota/core'; | ||
|
||
function MyCoins(): React.JSX.Element { | ||
const { openPopup, closePopup } = usePopups(); | ||
const account = useCurrentAccount(); | ||
const activeAccountAddress = account?.address; | ||
|
||
const { data: coinBalances } = useIotaClientQuery( | ||
'getAllBalances', | ||
{ owner: activeAccountAddress! }, | ||
{ | ||
enabled: !!activeAccountAddress, | ||
staleTime: COINS_QUERY_STALE_TIME, | ||
refetchInterval: COINS_QUERY_REFETCH_INTERVAL, | ||
select: filterAndSortTokenBalances, | ||
}, | ||
); | ||
const { recognized, unrecognized } = useSortedCoinsByCategories(coinBalances ?? []); | ||
|
||
function openSendTokenPopup(coin: CoinBalance, address: string): void { | ||
if (coinBalances) { | ||
openPopup( | ||
<SendCoinPopup | ||
coin={coin} | ||
senderAddress={address} | ||
onClose={closePopup} | ||
coins={coinBalances} | ||
/>, | ||
); | ||
} | ||
} | ||
|
||
return ( | ||
<div className="flex w-2/3 flex-col items-center space-y-2"> | ||
<h3>My Coins:</h3> | ||
{recognized?.map((coin, index) => { | ||
return ( | ||
<CoinItem | ||
key={index} | ||
coinType={coin.coinType} | ||
balance={BigInt(coin.totalBalance)} | ||
onClick={() => openSendTokenPopup(coin, account?.address ?? '')} | ||
/> | ||
); | ||
})} | ||
<span>Unrecognized coins</span> | ||
{unrecognized?.map((coin, index) => { | ||
return ( | ||
<CoinItem | ||
key={index} | ||
coinType={coin.coinType} | ||
balance={BigInt(coin.totalBalance)} | ||
onClick={() => openSendTokenPopup(coin, account?.address ?? '')} | ||
/> | ||
); | ||
})} | ||
</div> | ||
); | ||
} | ||
|
||
export default MyCoins; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export { default as AllCoins } from './AllCoins'; | ||
export { default as MyCoins } from './MyCoins'; | ||
export { default as CoinItem } from './CoinItem'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React from 'react'; | ||
|
||
interface DropdownProps<T> { | ||
options: T[]; | ||
selectedOption: T | null | undefined; | ||
onChange: (selectedOption: T) => void; | ||
placeholder?: string; | ||
disabled?: boolean; | ||
getOptionId: (option: T) => string | number; | ||
} | ||
|
||
function Dropdown<T>({ | ||
options, | ||
selectedOption, | ||
onChange, | ||
placeholder, | ||
disabled = false, | ||
getOptionId, | ||
}: DropdownProps<T>): JSX.Element { | ||
function handleSelectionChange(e: React.ChangeEvent<HTMLSelectElement>): void { | ||
const selectedKey = e.target.value; | ||
const selectedOption = options.find((option) => getOptionId(option) === selectedKey); | ||
if (selectedOption) { | ||
onChange(selectedOption); | ||
} | ||
} | ||
|
||
return ( | ||
<select | ||
value={selectedOption ? getOptionId(selectedOption) : ''} | ||
onChange={handleSelectionChange} | ||
className="px-2 py-3" | ||
disabled={disabled} | ||
> | ||
{placeholder && ( | ||
<option value="" disabled> | ||
{placeholder} | ||
</option> | ||
)} | ||
|
||
{options.map((option, index) => ( | ||
<option key={index} value={getOptionId(option)}> | ||
{getOptionId(option)} | ||
</option> | ||
))} | ||
</select> | ||
); | ||
} | ||
|
||
export default Dropdown; |
Oops, something went wrong.