-
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): style migration flow (#4510)
* feat(dashboard): add migration overview * feat: refine values * fix: update summarizeMigratableObjectValues function * feat(dashboard): add migratable object details * feat: add object details * fix: add missing type * feat: use react query to cache data * refactor: show expiration label correctly * feat: add missing asset fallback * feat: simplify code, add correct timestamps * fix: remove package id * fix: bring back missing logic * fix: remove unnecesary memos and improve skeleton * feat: create migration dialog * feat: style * perf: fetch objects in chunks * fix props * feat: refine dialog * feat: refine dialog styles * cleanup * fix import * feat: add totalStorageDepositReturnAmount * feat: fix virtual list and remove duplicated import * feat: update storage deposit return amount * fix format * feat: improve naming and make onSuccess not optional * feat: rmeove debris * feat: update names * feat: remove debris after merge * chore: rename function --------- Co-authored-by: JCNoguera <[email protected]> Co-authored-by: Marc Espin <[email protected]> Co-authored-by: Begoña Alvarez <[email protected]>
- Loading branch information
Showing
19 changed files
with
241 additions
and
252 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
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
176 changes: 176 additions & 0 deletions
176
apps/wallet-dashboard/components/Dialogs/MigrationDialog.tsx
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,176 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React from 'react'; | ||
import { VirtualList } from '@/components'; | ||
import { useCurrentAccount, useSignAndExecuteTransaction } from '@iota/dapp-kit'; | ||
import { IotaObjectData } from '@iota/iota-sdk/client'; | ||
import { useMigrationTransaction } from '@/hooks/useMigrationTransaction'; | ||
import { | ||
Button, | ||
Dialog, | ||
Header, | ||
InfoBox, | ||
InfoBoxStyle, | ||
InfoBoxType, | ||
KeyValueInfo, | ||
LoadingIndicator, | ||
Panel, | ||
Title, | ||
TitleSize, | ||
} from '@iota/apps-ui-kit'; | ||
import { useGroupedMigrationObjectsByExpirationDate } from '@/hooks'; | ||
import { Loader, Warning } from '@iota/ui-icons'; | ||
import { DialogLayout, DialogLayoutBody, DialogLayoutFooter } from './layout'; | ||
import { MigrationObjectDetailsCard } from '../migration/migration-object-details-card'; | ||
import { Collapsible, useFormatCoin } from '@iota/core'; | ||
import { IOTA_TYPE_ARG } from '@iota/iota-sdk/utils'; | ||
import { summarizeMigratableObjectValues } from '@/lib/utils'; | ||
import toast from 'react-hot-toast'; | ||
|
||
interface MigrationDialogProps { | ||
basicOutputObjects: IotaObjectData[] | undefined; | ||
nftOutputObjects: IotaObjectData[] | undefined; | ||
onSuccess: (digest: string) => void; | ||
setOpen: (bool: boolean) => void; | ||
open: boolean; | ||
isTimelocked: boolean; | ||
} | ||
|
||
export function MigrationDialog({ | ||
basicOutputObjects = [], | ||
nftOutputObjects = [], | ||
onSuccess, | ||
open, | ||
setOpen, | ||
isTimelocked, | ||
}: MigrationDialogProps): JSX.Element { | ||
const account = useCurrentAccount(); | ||
const { | ||
data: migrateData, | ||
isPending: isMigrationPending, | ||
isError: isMigrationError, | ||
} = useMigrationTransaction(account?.address || '', basicOutputObjects, nftOutputObjects); | ||
|
||
const { | ||
data: resolvedObjects = [], | ||
isLoading, | ||
error: isGroupedMigrationError, | ||
} = useGroupedMigrationObjectsByExpirationDate( | ||
[...basicOutputObjects, ...nftOutputObjects], | ||
isTimelocked, | ||
); | ||
|
||
const { mutateAsync: signAndExecuteTransaction, isPending: isSendingTransaction } = | ||
useSignAndExecuteTransaction(); | ||
const { totalNotOwnedStorageDepositReturnAmount } = summarizeMigratableObjectValues({ | ||
basicOutputs: basicOutputObjects, | ||
nftOutputs: nftOutputObjects, | ||
address: account?.address || '', | ||
}); | ||
|
||
const [gasFee, gasFeeSymbol] = useFormatCoin(migrateData?.gasBudget, IOTA_TYPE_ARG); | ||
const [totalStorageDepositReturnAmountFormatted, totalStorageDepositReturnAmountSymbol] = | ||
useFormatCoin(totalNotOwnedStorageDepositReturnAmount.toString(), IOTA_TYPE_ARG); | ||
|
||
async function handleMigrate(): Promise<void> { | ||
if (!migrateData) return; | ||
signAndExecuteTransaction( | ||
{ | ||
transaction: migrateData.transaction, | ||
}, | ||
{ | ||
onSuccess: (tx) => { | ||
onSuccess(tx.digest); | ||
}, | ||
}, | ||
) | ||
.then(() => { | ||
toast.success('Migration transaction has been sent'); | ||
}) | ||
.catch(() => { | ||
toast.error('Migration transaction was not sent'); | ||
}); | ||
} | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={setOpen}> | ||
<DialogLayout> | ||
<Header title="Confirmation" onClose={() => setOpen(false)} titleCentered /> | ||
<DialogLayoutBody> | ||
<div className="flex h-full flex-col gap-y-md overflow-y-auto"> | ||
{isGroupedMigrationError && !isLoading && ( | ||
<InfoBox | ||
title="Error" | ||
supportingText="Failed to load migration objects" | ||
style={InfoBoxStyle.Elevated} | ||
type={InfoBoxType.Error} | ||
icon={<Warning />} | ||
/> | ||
)} | ||
{isLoading ? ( | ||
<LoadingIndicator text="Loading migration objects" /> | ||
) : ( | ||
<> | ||
<Collapsible | ||
defaultOpen | ||
render={() => ( | ||
<Title size={TitleSize.Small} title="Assets to Migrate" /> | ||
)} | ||
> | ||
<div className="h-[600px] pb-md--rs"> | ||
<VirtualList | ||
heightClassName="h-full" | ||
overflowClassName="overflow-y-auto" | ||
items={resolvedObjects} | ||
estimateSize={() => 58} | ||
render={(migrationObject) => ( | ||
<MigrationObjectDetailsCard | ||
migrationObject={migrationObject} | ||
isTimelocked={isTimelocked} | ||
/> | ||
)} | ||
/> | ||
</div> | ||
</Collapsible> | ||
<Panel hasBorder> | ||
<div className="flex flex-col gap-y-sm p-md"> | ||
<KeyValueInfo | ||
keyText="Legacy storage deposit" | ||
value={totalStorageDepositReturnAmountFormatted || '-'} | ||
supportingLabel={totalStorageDepositReturnAmountSymbol} | ||
fullwidth | ||
/> | ||
<KeyValueInfo | ||
keyText="Gas Fees" | ||
value={gasFee || '-'} | ||
supportingLabel={gasFeeSymbol} | ||
fullwidth | ||
/> | ||
</div> | ||
</Panel> | ||
</> | ||
)} | ||
</div> | ||
</DialogLayoutBody> | ||
<DialogLayoutFooter> | ||
<Button | ||
text="Migrate" | ||
disabled={isMigrationPending || isMigrationError || isSendingTransaction} | ||
onClick={handleMigrate} | ||
icon={ | ||
isMigrationPending || isSendingTransaction ? ( | ||
<Loader | ||
className="h-4 w-4 animate-spin" | ||
data-testid="loading-indicator" | ||
/> | ||
) : null | ||
} | ||
iconAfterText | ||
fullWidth | ||
/> | ||
</DialogLayoutFooter> | ||
</DialogLayout> | ||
</Dialog> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.