-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: WalletConnect integration, request
requests are supported. Tested: - send tez - delegate / UndelegationSignPage - originate / call contract - stake / unstake / finalize unstake
- Loading branch information
1 parent
8fbd220
commit 1bf9402
Showing
17 changed files
with
281 additions
and
65 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
53 changes: 53 additions & 0 deletions
53
apps/web/src/components/SendFlow/WalletConnect/useSignWithWc.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,53 @@ | ||
import { type TezosToolkit } from "@taquito/taquito"; | ||
import { useDynamicModalContext } from "@umami/components"; | ||
import { executeOperations, totalFee } from "@umami/core"; | ||
import { useAsyncActionHandler, walletKit } from "@umami/state"; | ||
import { formatJsonRpcResult } from "@walletconnect/jsonrpc-utils"; | ||
import { useForm } from "react-hook-form"; | ||
|
||
import { SuccessStep } from "../SuccessStep"; | ||
import { type CalculatedSignProps, type SdkSignPageProps } from "../utils"; | ||
|
||
export const useSignWithWalletConnect = ({ | ||
operation, | ||
headerProps, | ||
requestId, | ||
}: SdkSignPageProps): CalculatedSignProps => { | ||
const { isLoading: isSigning, handleAsyncAction } = useAsyncActionHandler(); | ||
const { openWith } = useDynamicModalContext(); | ||
|
||
const form = useForm({ defaultValues: { executeParams: operation.estimates } }); | ||
|
||
if (requestId.sdkType !== "walletconnect") { | ||
return { | ||
fee: 0, | ||
isSigning: false, | ||
onSign: async () => {}, | ||
network: null, | ||
}; | ||
} | ||
|
||
const onSign = async (tezosToolkit: TezosToolkit) => | ||
handleAsyncAction( | ||
async () => { | ||
const { opHash } = await executeOperations( | ||
{ ...operation, estimates: form.watch("executeParams") }, | ||
tezosToolkit | ||
); | ||
|
||
const response = formatJsonRpcResult(requestId.id, { hash: opHash }); | ||
await walletKit.respondSessionRequest({ topic: requestId.topic, response }); | ||
return openWith(<SuccessStep hash={opHash} />); | ||
}, | ||
error => ({ | ||
description: `Failed to confirm Beacon operation: ${error.message}`, | ||
}) | ||
); | ||
|
||
return { | ||
fee: totalFee(form.watch("executeParams")), | ||
isSigning, | ||
onSign, | ||
network: headerProps.network, | ||
}; | ||
}; |
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 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 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
Oops, something went wrong.