-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Why: We want to implement a delegated AG mechanism so it is citizend to support the fees of inserting the grants in the blockchain. This change addresses the need by: - Calling the smartcontract from the UI with insertGrantBySignatureMessage that retrieves a message for the user to sign, granting the required permission for the projects to user later on - Make User signing the message - Send result to our server and call insertGrantBySignature, which closes the flow, by making our server wallet pay the transaction and inserts the AG from the user to the project in the blockchain
- Loading branch information
1 parent
9c3ca01
commit 5823128
Showing
12 changed files
with
500 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { useFetchNewDataId } from './queries'; | ||
import { useReadContract } from 'wagmi'; | ||
import { grantsAbi } from '../_server/grants/abi'; | ||
import { useMemo } from 'react'; | ||
|
||
type TFetchGrantMessage = { | ||
owner: string | undefined; | ||
grantee: string | undefined; | ||
dataId: string | undefined; | ||
expiration: number | undefined; | ||
message: string | undefined; | ||
isSuccess: boolean; | ||
isError: boolean; | ||
isLoading: boolean; | ||
}; | ||
|
||
/** generate a grant message to be signed by the user and later inserted by our server | ||
*/ | ||
export const useFetchGrantMessage = (): TFetchGrantMessage => { | ||
const { data, isSuccess: isSuccessDataId } = useFetchNewDataId(); | ||
const { | ||
data: message, | ||
isSuccess: isSuccessMessage, | ||
isError, | ||
isLoading, | ||
} = useReadContract({ | ||
abi: grantsAbi, | ||
address: process.env.NEXT_PUBLIC_IDOS_CONTRACT_ADDRESS, | ||
functionName: 'insertGrantBySignatureMessage', | ||
args: [data?.owner, data?.grantee, data?.dataId, data?.expiration], | ||
query: { | ||
enabled: !!( | ||
isSuccessDataId && | ||
data?.owner && | ||
data?.grantee && | ||
data?.dataId && | ||
data?.expiration | ||
), | ||
}, | ||
}); | ||
|
||
return useMemo(() => { | ||
return { | ||
owner: data?.owner, | ||
grantee: data?.grantee, | ||
dataId: data?.dataId, | ||
expiration: data?.expiration, | ||
message: message as string | undefined, //review later | ||
isSuccess: isSuccessMessage, | ||
isError, | ||
isLoading, | ||
}; | ||
}, [ | ||
message, | ||
isSuccessMessage, | ||
isError, | ||
isLoading, | ||
data?.owner, | ||
data?.grantee, | ||
data?.dataId, | ||
data?.expiration, | ||
]); | ||
}; |
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.