-
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.
Merge branch 'develop' into dev-tools/test-data-alias-ownership
- Loading branch information
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.