Skip to content

Commit 7d7a2d9

Browse files
evavirsedamsarcev
andauthored
feat: add toast feedback for actions in dapp (#452)
* add support for toasts * fix build * add purchase toast * minor fix * add more toasts * add toasts for avatar and renew * add missing toasts * fix build * update success page for unlinking an address * fix build * fix build * fix build --------- Co-authored-by: msarcev <mario.sarcevic@iota.org>
1 parent 0fae96c commit 7d7a2d9

File tree

7 files changed

+82
-8
lines changed

7 files changed

+82
-8
lines changed

dapp/src/auctions/components/dialogs/AuctionBidDialog.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { Transaction } from '@iota/iota-sdk/transactions';
2929
import { IOTA_DECIMALS } from '@iota/iota-sdk/utils';
3030
import { useMutation, useQueryClient } from '@tanstack/react-query';
3131
import { useEffect, useState } from 'react';
32+
import toast from 'react-hot-toast';
3233

3334
import { useAuctionBid } from '@/auctions/hooks/useAuctionBid';
3435
import { useCountdown } from '@/auctions/hooks/useCountdown';
@@ -111,9 +112,18 @@ export function AuctionBidDialog({ name, closeDialog, onCompleted }: AuctionBidD
111112
queryKey: queryKey.userAuctionHistory(account?.address),
112113
});
113114
queryClient.invalidateQueries({ queryKey: queryKey.auctionMetadata(name) });
115+
toast.success(
116+
`Successfully placed bid of ${formatNanosToIota(bidNanos ?? 0, {
117+
formatRounded: false,
118+
showIotaSymbol: true,
119+
})} on ${normalizeIotaName(name)}`,
120+
);
114121
closeDialog();
115122
onCompleted?.();
116123
},
124+
onError(err) {
125+
toast.error(err.message);
126+
},
117127
});
118128

119129
const hasEnoughGas =

dapp/src/components/dialogs/ConnectToAddressDialog.tsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { isSubname, normalizeIotaName } from '@iota/iota-names-sdk';
3030
import { formatAddress, isValidIotaAddress } from '@iota/iota-sdk/utils';
3131
import { useMutation, useQueryClient } from '@tanstack/react-query';
3232
import { ChangeEvent, useEffect, useState } from 'react';
33+
import toast from 'react-hot-toast';
3334

3435
import { NameRecordData, queryKey, useNameRecord, useRegistrationNfts } from '@/hooks';
3536
import { useGetDefaultName } from '@/hooks/useGetDefaultName';
@@ -127,6 +128,18 @@ export function ConnectToAddressDialog({ name, setOpen }: ConnectToAddressDialog
127128
queryClient.invalidateQueries({
128129
queryKey: queryKey.defaultName(account?.address || ''),
129130
});
131+
if (editTargetAddress.length === 0) {
132+
toast.success(`Successfully disconnected ${cleanName}`);
133+
setOpen(false);
134+
} else if (editTargetAddress !== account?.address) {
135+
toast.success(
136+
`Successfully connected ${cleanName} to address ${formatAddress(editTargetAddress)}`,
137+
);
138+
setOpen(false);
139+
}
140+
},
141+
onError: (error) => {
142+
toast.error(error.message);
130143
},
131144
});
132145

@@ -169,19 +182,27 @@ export function ConnectToAddressDialog({ name, setOpen }: ConnectToAddressDialog
169182
{isSuccess ? (
170183
<div className="flex flex-col gap-y-md items-center text-center">
171184
<div className="flex flex-col items-center gap-y-sm">
172-
<span className="text-title-lg text-names-neutral-100">
173-
{normalizeIotaName(name)}
174-
</span>
185+
{editIsDefaultName ? (
186+
<span className="text-title-lg text-names-neutral-100">
187+
{cleanName}
188+
</span>
189+
) : null}
175190
<Chip
176191
leadingElement={<Link className="w-4 h-4" />}
177192
label={formatAddress(account?.address || '')}
178193
trailingElement={<Copy className="w-4 h-4" />}
179194
onClick={copyAddressToClipboard}
180-
type={ChipType.Success}
195+
type={
196+
editIsDefaultName
197+
? ChipType.Success
198+
: ChipType.Elevated
199+
}
181200
/>
182201
</div>
183202
<span className="text-body-md text-names-neutral-70">
184-
Address linked successfully
203+
{editIsDefaultName
204+
? 'Address linked successfully'
205+
: `${cleanName} is no longer linked to an address`}
185206
</span>
186207
</div>
187208
) : (

dapp/src/components/dialogs/CreateSubnameDialog.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
} from '@iota/iota-names-sdk';
3131
import { useMutation, useQueryClient } from '@tanstack/react-query';
3232
import { ChangeEvent, useState } from 'react';
33+
import toast from 'react-hot-toast';
3334

3435
import { NameRecordData, queryKey, useNameRecord, useRegistrationNfts } from '@/hooks';
3536
import { NameUpdate, useUpdateNameTransaction } from '@/hooks/useUpdateNameTransaction';
@@ -158,8 +159,12 @@ export function CreateSubnameDialog({ name, setOpen }: CreateSubnameProps) {
158159
queryClient.invalidateQueries({
159160
queryKey: queryKey.ownedObjects(account?.address || ''),
160161
});
162+
toast.success(`Successfully created subname @${fullSubnameName}`);
161163
closeDialog();
162164
},
165+
onError: (error) => {
166+
toast.error(error.message);
167+
},
163168
});
164169

165170
function closeDialog() {

dapp/src/components/dialogs/DeleteNameDialog.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { useCurrentAccount, useIotaClient, useSignAndExecuteTransaction } from '
2222
import { isSubname, normalizeIotaName } from '@iota/iota-names-sdk';
2323
import { useMutation, useQueryClient } from '@tanstack/react-query';
2424
import { useEffect, useState } from 'react';
25+
import toast from 'react-hot-toast';
2526

2627
import { useRegistrationNfts } from '@/hooks';
2728
import { queryKey } from '@/hooks/queryKey';
@@ -85,8 +86,12 @@ export function DeleteNameDialog({ nft, setOpen }: DeleteNameDialogProps) {
8586
queryClient.invalidateQueries({
8687
queryKey: queryKey.ownedObjects(account?.address || ''),
8788
});
89+
toast.success(`Successfully deleted expired name ${normalizeIotaName(nft.name)}`);
8890
closeDialog();
8991
},
92+
onError: (error) => {
93+
toast.error(error.message);
94+
},
9095
});
9196

9297
function closeDialog() {

dapp/src/components/dialogs/PersonalizeAvatarDialog.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import {
1818
VisualAssetCard,
1919
} from '@iota/apps-ui-kit';
2020
import { useCurrentAccount, useIotaClient, useSignAndExecuteTransaction } from '@iota/dapp-kit';
21-
import { isSubname } from '@iota/iota-names-sdk';
21+
import { isSubname, normalizeIotaName } from '@iota/iota-names-sdk';
2222
import { useMutation, useQueryClient } from '@tanstack/react-query';
2323
import { useState } from 'react';
24+
import toast from 'react-hot-toast';
2425

2526
import { BrandedAssets } from '@/components/svgs';
2627
import {
@@ -98,6 +99,10 @@ export function PersonalizeAvatarDialog({ name, setOpen }: PersonalizeAvatarDial
9899
},
99100
onSuccess() {
100101
setOpen(false);
102+
toast.success(`Successfully updated avatar for ${normalizeIotaName(name)}`);
103+
},
104+
onError: (error) => {
105+
toast.error(error.message);
101106
},
102107
});
103108

dapp/src/components/dialogs/PurchaseNameDialog.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import {
2525
import { useCurrentAccount, useIotaClient, useSignAndExecuteTransaction } from '@iota/dapp-kit';
2626
import { normalizeIotaName } from '@iota/iota-names-sdk';
2727
import { useMutation, useQueryClient } from '@tanstack/react-query';
28-
import { useState } from 'react';
28+
import { useEffect, useState } from 'react';
29+
import toast from 'react-hot-toast';
2930

3031
import { NameUpdate, queryKey, useBalanceValidation, useUpdateNameTransaction } from '@/hooks';
3132
import { useCoreConfig } from '@/hooks/useCoreConfig';
@@ -116,11 +117,14 @@ export function PurchaseNameDialog({ name, open, setOpen, onPurchase }: Purchase
116117
queryClient.invalidateQueries({
117118
queryKey: queryKey.ownedObjects(account?.address || ''),
118119
});
119-
120+
toast.success(`Successfully registered name ${normalizeIotaName(name)}`);
120121
setOpen(false);
121122

122123
if (onPurchase) onPurchase();
123124
},
125+
onError(error) {
126+
toast.error(error.message);
127+
},
124128
});
125129

126130
function closeDialog() {
@@ -154,6 +158,25 @@ export function PurchaseNameDialog({ name, open, setOpen, onPurchase }: Purchase
154158

155159
const expirationDate = getTargetExpirationDate(renewYears);
156160

161+
useEffect(() => {
162+
if (nameRecordError) {
163+
toast.error(nameRecordError.message);
164+
}
165+
}, [nameRecordError]);
166+
167+
useEffect(() => {
168+
if (updateNameError) {
169+
if (
170+
updateNameError.message.includes(GAS_BALANCE_TOO_LOW_ID) ||
171+
updateNameError.message.includes(NOT_ENOUGH_BALANCE_ID)
172+
) {
173+
toast.error(GAS_BUDGET_ERROR_MESSAGES[GAS_BALANCE_TOO_LOW_ID]);
174+
} else {
175+
toast.error(updateNameError.message);
176+
}
177+
}
178+
}, [updateNameError]);
179+
157180
return (
158181
<Dialog open={open} onOpenChange={setOpen}>
159182
<DialogContent containerId="overlay-portal-container" position={DialogPosition.Right}>

dapp/src/components/dialogs/RenewNameDialog.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { useCurrentAccount, useIotaClient, useSignAndExecuteTransaction } from '
2525
import { isSubname, NameRecord, normalizeIotaName } from '@iota/iota-names-sdk';
2626
import { useMutation, useQueryClient } from '@tanstack/react-query';
2727
import { useEffect, useState } from 'react';
28+
import toast from 'react-hot-toast';
2829

2930
import { NameRecordData, queryKey, useNameRecord, useRegistrationNfts } from '@/hooks';
3031
import { useCoreConfig } from '@/hooks/useCoreConfig';
@@ -150,6 +151,10 @@ export function RenewNameDialog({ setOpen, name }: RenewDialogProps) {
150151
queryClient.invalidateQueries({
151152
queryKey: queryKey.nameRecord(name),
152153
});
154+
toast.success('Name renewed successfully');
155+
},
156+
onError(error) {
157+
toast.error(error.message);
153158
},
154159
});
155160

0 commit comments

Comments
 (0)