-
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.
* fix(dw): sign request * fix(dw): sign request
- Loading branch information
Showing
3 changed files
with
106 additions
and
32 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
103 changes: 103 additions & 0 deletions
103
packages/apps/dev-wallet/src/pages/transaction/sign-request.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,103 @@ | ||
import { ITransaction } from '@/modules/transaction/transaction.repository'; | ||
|
||
import { SideBarBreadcrumbs } from '@/Components/SideBarBreadcrumbs/SideBarBreadcrumbs'; | ||
import { useRequests } from '@/modules/communication/communication.provider'; | ||
import { addTransaction } from '@/modules/transaction/transaction.service'; | ||
import { useWallet } from '@/modules/wallet/wallet.hook'; | ||
import { usePatchedNavigate } from '@/utils/usePatchedNavigate'; | ||
import { IPactCommand, IUnsignedCommand } from '@kadena/client'; | ||
import { MonoSwapHoriz } from '@kadena/kode-icons/system'; | ||
import { Heading, Notification, Stack, Text } from '@kadena/kode-ui'; | ||
import { SideBarBreadcrumbsItem } from '@kadena/kode-ui/patterns'; | ||
import { useEffect, useState } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { TxList } from './components/TxList'; | ||
|
||
export const SignRequest = () => { | ||
const navigate = usePatchedNavigate(); | ||
const { profile, networks, activeNetwork } = useWallet(); | ||
const { requestId } = useParams(); | ||
const requests = useRequests(); | ||
const [tx, setTx] = useState<ITransaction>(); | ||
const [error, setError] = useState<string | undefined>(); | ||
|
||
useEffect(() => { | ||
const run = async () => { | ||
if (profile?.uuid && requestId) { | ||
const tx = requests.get(requestId)?.payload as IUnsignedCommand; | ||
if (!tx) { | ||
setError('No transaction'); | ||
return; | ||
} | ||
const cmd: IPactCommand = JSON.parse(tx.cmd); | ||
const networkUUID = | ||
networks.find(({ networkId }) => networkId === cmd.networkId)?.uuid ?? | ||
activeNetwork?.uuid; | ||
|
||
if (!networkUUID) { | ||
setError(`Network not found for ${cmd.networkId}`); | ||
return; | ||
} | ||
|
||
const transaction = await addTransaction({ | ||
transaction: tx as IUnsignedCommand, | ||
profileId: profile?.uuid, | ||
networkUUID: networkUUID, | ||
groupId: requestId, | ||
}); | ||
|
||
setTx(transaction); | ||
} | ||
}; | ||
run(); | ||
}, [ | ||
requestId, | ||
navigate, | ||
profile?.uuid, | ||
requests, | ||
networks, | ||
activeNetwork?.uuid, | ||
]); | ||
|
||
return ( | ||
<> | ||
<SideBarBreadcrumbs icon={<MonoSwapHoriz />}> | ||
<SideBarBreadcrumbsItem href={`/transactions`}> | ||
Activities | ||
</SideBarBreadcrumbsItem> | ||
<SideBarBreadcrumbsItem href={`/sign-request/${requestId}`}> | ||
Sign Request | ||
</SideBarBreadcrumbsItem> | ||
</SideBarBreadcrumbs> | ||
|
||
{error ? ( | ||
<Notification intent="negative" role="alert"> | ||
{error} | ||
</Notification> | ||
) : ( | ||
<Stack flexDirection={'column'} gap={'lg'} overflow="auto"> | ||
<Stack flexDirection={'column'} gap={'sm'}> | ||
<Heading>Transaction</Heading> | ||
{!tx && <Text>No transaction</Text>} | ||
</Stack> | ||
<TxList | ||
onDone={() => { | ||
console.log('done'); | ||
}} | ||
txIds={tx ? [tx.uuid] : []} | ||
showExpanded={true} | ||
onSign={(tx) => { | ||
if (requestId) { | ||
const request = requests.get(requestId); | ||
if (request) { | ||
console.log('resolving request', request); | ||
request.resolve({ status: 'signed', transaction: tx }); | ||
} | ||
} | ||
}} | ||
/> | ||
</Stack> | ||
)} | ||
</> | ||
); | ||
}; |