-
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.
feat: Enable T&C in create instance message (#112)
* deps: upgrade sdk message to v1.3.1 * feat: send terms_and_conditions on VM creation * docs: explain why modalOpen and modalClose are excluded from deps * fix: don't show modal when switch to hold
- Loading branch information
Showing
8 changed files
with
167 additions
and
82 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { useAppState } from '@/contexts/appState' | ||
import { StoreContent } from '@aleph-sdk/message' | ||
import { useEffect, useState } from 'react' | ||
|
||
export type TermsAndConditions = { | ||
cid: string | ||
name: string | ||
url: string | ||
} | ||
|
||
export type UseFetchTermsAndConditionsProps = { | ||
termsAndConditionsMessageHash?: string | ||
} | ||
|
||
export type UseFetchTermsAndConditionsReturn = { | ||
loading: boolean | ||
termsAndConditions?: TermsAndConditions | ||
} | ||
|
||
export default function useFetchTermsAndConditions({ | ||
termsAndConditionsMessageHash, | ||
}: UseFetchTermsAndConditionsProps): UseFetchTermsAndConditionsReturn { | ||
const [state] = useAppState() | ||
const { | ||
manager: { messageManager }, | ||
} = state | ||
|
||
const [loading, setLoading] = useState(true) | ||
const [termsAndConditions, setTermsAndConditions] = useState< | ||
TermsAndConditions | undefined | ||
>() | ||
|
||
useEffect(() => { | ||
const fetchTermsAndConditions = async () => { | ||
try { | ||
if (!messageManager) return setTermsAndConditions(undefined) | ||
if (!termsAndConditionsMessageHash) | ||
return setTermsAndConditions(undefined) | ||
|
||
setLoading(true) | ||
|
||
let storeMessageContent | ||
try { | ||
const { content } = await messageManager.get( | ||
termsAndConditionsMessageHash, | ||
) | ||
storeMessageContent = content as StoreContent | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
|
||
if (!storeMessageContent) return setTermsAndConditions(undefined) | ||
|
||
const cid = storeMessageContent.item_hash | ||
const name = storeMessageContent.metadata?.name as string | ||
|
||
setTermsAndConditions({ | ||
cid, | ||
name, | ||
url: `https://ipfs.aleph.im/ipfs/${cid}?filename=${name}`, | ||
}) | ||
} catch (e) { | ||
console.error(e) | ||
} finally { | ||
setLoading(false) | ||
} | ||
} | ||
|
||
fetchTermsAndConditions() | ||
}, [messageManager, termsAndConditionsMessageHash]) | ||
|
||
return { | ||
loading, | ||
termsAndConditions, | ||
} | ||
} |
Oops, something went wrong.