Skip to content

Commit

Permalink
refactor: move fuelSign into utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-stumpf committed Jul 29, 2024
1 parent 960550d commit 03f1d7c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 31 deletions.
27 changes: 0 additions & 27 deletions src/hooks/useSubmit/fuelSign.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/hooks/useSubmit/useSubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import { useCallback, useState } from "react"
import useSWR from "swr"
import { useChainId, usePublicClient, useWalletClient } from "wagmi"
import { DEFAULT_MESSAGE, DEFAULT_SIGN_LOADING_TEXT } from "./constants"
import { fuelSign } from "./fuelSign"
import { SignProps, UseSubmitOptions, Validation } from "./types"
import { getMessage, sign } from "./utils"
import { fuelSign, getMessage, sign } from "./utils"
import gnosisSafeSignCallback from "./utils/gnosisSafeSignCallback"

type FetcherFunction<ResponseType> = ({
Expand Down
25 changes: 24 additions & 1 deletion src/hooks/useSubmit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { wagmiConfig } from "wagmiConfig"
import { Chain, Chains, supportedChains } from "wagmiConfig/chains"
import { DEFAULT_MESSAGE } from "./constants"
import { MessageParams, SignProps, Validation } from "./types"
import { FuelSignProps, MessageParams, SignProps, Validation } from "./types"

export const signWithKeyPair = (keyPair: CryptoKeyPair, params: MessageParams) =>
window.crypto.subtle
Expand Down Expand Up @@ -151,3 +151,26 @@ export const chainsOfAddressWithDeployedContract = async (

return res
}

export const fuelSign = async ({
wallet,
address,
payload,
keyPair,
forcePrompt,
msg = DEFAULT_MESSAGE,
ts,
}: FuelSignProps): Promise<[string, Validation]> => {
const params = createMessageParams(address, ts, msg, payload)
let sig = null

if (!!keyPair && !forcePrompt) {
params.method = ValidationMethod.KEYPAIR
sig = await signWithKeyPair(keyPair, params)
} else {
params.method = ValidationMethod.FUEL
sig = await wallet.signMessage(getMessage(params))
}

return [payload, { params, sig }]
}
2 changes: 1 addition & 1 deletion src/utils/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { env } from "env"
import { fuelSign } from "hooks/useSubmit/fuelSign"
import { FuelSignProps, SignProps } from "hooks/useSubmit/types"
import { fuelSign } from "hooks/useSubmit/utils"
import { sign } from "hooks/useSubmit/utils"
import { pushToIntercomSetting } from "./intercom"

Expand Down

0 comments on commit 03f1d7c

Please sign in to comment.