-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rwa): add a message when a investor is frozen (#2779)
- Loading branch information
1 parent
9722418
commit 4d4d0ee
Showing
14 changed files
with
305 additions
and
103 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
67 changes: 0 additions & 67 deletions
67
packages/apps/rwa-demo/src/components/BadgeFeezeForm/BadgeFeezeForm.tsx
This file was deleted.
Oops, something went wrong.
117 changes: 117 additions & 0 deletions
117
packages/apps/rwa-demo/src/components/BadgeFreezeForm/BadgeFreezeForm.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,117 @@ | ||
import { useBatchFreezeInvestors } from '@/hooks/batchFreezeInvestors'; | ||
import type { IBatchSetAddressFrozenProps } from '@/services/batchSetAddressFrozen'; | ||
import { MonoPause, MonoPlayArrow } from '@kadena/kode-icons'; | ||
import { | ||
Button, | ||
Dialog, | ||
DialogContent, | ||
DialogFooter, | ||
DialogHeader, | ||
TextareaField, | ||
} from '@kadena/kode-ui'; | ||
|
||
import { useAccount } from '@/hooks/account'; | ||
import type { ChangeEvent, FC } from 'react'; | ||
import { useState } from 'react'; | ||
import type { UseFormHandleSubmit, UseFormReset } from 'react-hook-form'; | ||
import { TransactionTypeSpinner } from '../TransactionTypeSpinner/TransactionTypeSpinner'; | ||
import { TXTYPES } from '../TransactionsProvider/TransactionsProvider'; | ||
|
||
interface IProps { | ||
pause: boolean; | ||
isDisabled: boolean; | ||
handleReset: UseFormReset<{ | ||
select: []; | ||
}>; | ||
handleSubmit: UseFormHandleSubmit< | ||
{ | ||
select: []; | ||
}, | ||
undefined | ||
>; | ||
} | ||
|
||
export const BadgeFreezeForm: FC<IProps> = ({ | ||
handleSubmit, | ||
handleReset, | ||
isDisabled, | ||
pause, | ||
}) => { | ||
const [isModalOpen, setIsModalOpen] = useState<boolean>(false); | ||
const [message, setMessage] = useState<string>(''); | ||
const { account } = useAccount(); | ||
const { submit, isAllowed } = useBatchFreezeInvestors(); | ||
|
||
const onSubmit = async ({ select }: { select: string[] }) => { | ||
const data: IBatchSetAddressFrozenProps = { | ||
investorAccounts: select, | ||
pause, | ||
message, | ||
}; | ||
const tx = await submit(data); | ||
setIsModalOpen(false); | ||
tx?.listener.subscribe( | ||
() => {}, | ||
() => {}, | ||
() => { | ||
handleReset({ select: [] }); | ||
}, | ||
); | ||
}; | ||
|
||
const handleMessageChange = (e: ChangeEvent) => { | ||
setMessage((e.target as HTMLTextAreaElement).value); | ||
}; | ||
|
||
const handleStart = async () => { | ||
if (pause) { | ||
setIsModalOpen(true); | ||
return; | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
{pause && ( | ||
<Dialog isOpen={isModalOpen} onOpenChange={() => setIsModalOpen(false)}> | ||
<DialogHeader>Freeze selected accounts</DialogHeader> | ||
<DialogContent> | ||
<TextareaField | ||
onChange={handleMessageChange} | ||
label="message" | ||
maxLength={100} | ||
rows={5} | ||
/> | ||
</DialogContent> | ||
<DialogFooter> | ||
<Button variant="outlined" onPress={() => setIsModalOpen(false)}> | ||
Cancel | ||
</Button> | ||
<Button | ||
onClick={handleSubmit(onSubmit)} | ||
isDisabled={isDisabled || !isAllowed} | ||
variant="primary" | ||
> | ||
Freeze | ||
</Button> | ||
</DialogFooter> | ||
</Dialog> | ||
)} | ||
<Button | ||
isDisabled={isDisabled || !isAllowed} | ||
onClick={pause ? handleStart : handleSubmit(onSubmit)} | ||
isCompact | ||
variant="outlined" | ||
endVisual={ | ||
<TransactionTypeSpinner | ||
type={[TXTYPES.FREEZEINVESTOR]} | ||
account={account?.address} | ||
fallbackIcon={pause ? <MonoPlayArrow /> : <MonoPause />} | ||
/> | ||
} | ||
> | ||
{pause ? 'Freeze' : 'Unfreeze'} | ||
</Button> | ||
</> | ||
); | ||
}; |
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
9 changes: 9 additions & 0 deletions
9
packages/apps/rwa-demo/src/components/FrozenInvestorBanner/FrozenInvestorBanner.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,9 @@ | ||
import { useAccount } from '@/hooks/account'; | ||
import type { FC } from 'react'; | ||
import { InvestorFrozenMessage } from '../InvestorFrozenMessage/InvestorFrozenMessage'; | ||
|
||
export const FrozenInvestorBanner: FC = () => { | ||
const { account } = useAccount(); | ||
if (!account) return; | ||
return <InvestorFrozenMessage investorAccount={account.address} />; | ||
}; |
Oops, something went wrong.