-
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.
Merge pull request #15 from frak-id/feat/referral
Feat/referral
- Loading branch information
Showing
40 changed files
with
1,914 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@frak-labs/nexus-example": patch | ||
"@frak-labs/nexus-wallet": patch | ||
"@frak-labs/nexus-sdk": patch | ||
--- | ||
|
||
Add referral workflow |
39 changes: 39 additions & 0 deletions
39
packages/example/src/module/article/component/Popup/index.module.css
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,39 @@ | ||
.popup { | ||
align-items: center; | ||
color: #383f4e; | ||
display: flex; | ||
justify-content: center; | ||
left: 0; | ||
overflow: hidden; | ||
position: fixed; | ||
scroll-behavior: smooth; | ||
bottom: 0; | ||
width: 100%; | ||
z-index: 10000001; | ||
font-size: 16px; | ||
line-height: 24px; | ||
} | ||
|
||
.popup__content { | ||
background-color: #fff; | ||
display: flex; | ||
flex-direction: column; | ||
max-height: calc(100% - 80px); | ||
max-width: 978px; | ||
overflow: visible; | ||
margin: 10px; | ||
padding: 10px; | ||
position: relative; | ||
width: 100%; | ||
border-radius: 10px; | ||
border: 1px solid #e5e5e5; | ||
} | ||
|
||
.popup__explanation { | ||
color: #2a303b; | ||
font-size: 18px; | ||
line-height: 24px; | ||
margin-bottom: 20px; | ||
font-weight: 600; | ||
text-align: center; | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/example/src/module/article/component/Popup/index.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,37 @@ | ||
import css from "!!raw-loader!./index.module.css"; | ||
import { frakWalletSdkConfig } from "@/context/frak-wallet/config"; | ||
import { Button } from "@/module/common/component/Button"; | ||
import type { Article } from "@/type/Article"; | ||
|
||
export const cssRaw = css; | ||
|
||
function buildRedirectUrl(redirectUrl: string) { | ||
const outputUrl = new URL(frakWalletSdkConfig.walletUrl); | ||
outputUrl.pathname = "/register"; | ||
outputUrl.searchParams.set("redirectUrl", encodeURIComponent(redirectUrl)); | ||
return outputUrl.toString(); | ||
} | ||
|
||
export function Popup({ article }: { article: Article }) { | ||
return ( | ||
<div className={"popup"}> | ||
<div className={"popup__content"}> | ||
<p className={"popup__explanation"}> | ||
A Nexus user shared this link with you, create a Nexus | ||
account to instantly get 50rFRK | ||
</p> | ||
<Button | ||
variant={article.provider} | ||
size={"small"} | ||
onClick={() => { | ||
window.location.href = buildRedirectUrl( | ||
`${window.location.origin}/article?id=${article.id}` | ||
); | ||
}} | ||
> | ||
Connect or create a Nexus Wallet | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
} |
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
71 changes: 71 additions & 0 deletions
71
packages/example/src/module/article/component/Read/InjectPopupComponent.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,71 @@ | ||
import { Popup } from "@/module/article/component/Popup"; | ||
import { cssRaw as cssRawButton } from "@/module/common/component/Button"; | ||
import type { Article } from "@/type/Article"; | ||
import { useEffect, useState } from "react"; | ||
import { createPortal } from "react-dom"; | ||
import { cssRaw } from "../Popup"; | ||
|
||
export function InjectPopupComponent({ | ||
article, | ||
}: { | ||
article: Article; | ||
}) { | ||
const [containerRoot, setContainerRoot] = useState<Element | undefined>(); | ||
|
||
// Get the article's iframe | ||
const articleIframeName = "frak-article-iframe"; | ||
const articleIframe = document.querySelector( | ||
`#${articleIframeName}` | ||
) as HTMLIFrameElement; | ||
const articleIframeDocument = articleIframe?.contentWindow?.document; | ||
|
||
useEffect(() => { | ||
const containerName = "frak-popup"; | ||
let containerRoot = | ||
articleIframeDocument?.getElementById(containerName); | ||
|
||
// If the container does not exist, create it | ||
if (!containerRoot) { | ||
const appRoot = document.createElement("div"); | ||
appRoot.id = containerName; | ||
articleIframeDocument?.body?.insertAdjacentElement( | ||
"beforeend", | ||
appRoot | ||
); | ||
containerRoot = | ||
articleIframeDocument?.getElementById(containerName); | ||
|
||
if (containerRoot) { | ||
containerRoot.style.width = "100%"; | ||
setContainerRoot(containerRoot); | ||
} | ||
} | ||
}, [articleIframeDocument]); | ||
|
||
if ( | ||
!( | ||
articleIframe && | ||
articleIframeDocument && | ||
articleIframe.contentDocument | ||
) | ||
) { | ||
console.log(`iframe ${articleIframeName} not found`); | ||
return null; | ||
} | ||
|
||
return ( | ||
containerRoot && ( | ||
<> | ||
{createPortal(<Popup article={article} />, containerRoot)} | ||
{/* Inject the styles into the iframe */} | ||
{createPortal( | ||
<style> | ||
{cssRaw.toString()} | ||
{cssRawButton.toString()} | ||
</style>, | ||
articleIframe.contentDocument.head | ||
)} | ||
</> | ||
) | ||
); | ||
} |
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,31 @@ | ||
import type { Address, Hex } from "viem"; | ||
import type { NexusClient, SetUserReferredReturnType } from "../types"; | ||
|
||
/** | ||
* Type used to get the user referred options | ||
*/ | ||
export type SetUserReferredParams = { | ||
contentId: Hex; | ||
walletAddress: Address; | ||
}; | ||
|
||
/** | ||
* Function used to watch a current user referred | ||
* @param client | ||
* @param contentId | ||
* @param walletAddress | ||
* @param callback | ||
*/ | ||
export function setUserReferred( | ||
client: NexusClient, | ||
{ contentId, walletAddress }: SetUserReferredParams, | ||
callback: (status: SetUserReferredReturnType) => void | ||
) { | ||
return client.listenerRequest( | ||
{ | ||
method: "frak_listenToSetUserReferred", | ||
params: [contentId, walletAddress], | ||
}, | ||
callback | ||
); | ||
} |
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,28 @@ | ||
import type { Hex } from "viem"; | ||
|
||
/** | ||
* Parameters of the referred request | ||
*/ | ||
export type SetUserReferredParams = Readonly<{ | ||
contentId: Hex; | ||
}>; | ||
|
||
/** | ||
* Return type of the referred request | ||
*/ | ||
export type SetUserReferredReturnType = | ||
| UserIsSameWallet | ||
| UserReferredSuccessful | ||
| UserReferredHistory; | ||
|
||
type UserIsSameWallet = { | ||
key: "same-wallet"; | ||
}; | ||
|
||
type UserReferredSuccessful = { | ||
key: "referred-successful"; | ||
}; | ||
|
||
type UserReferredHistory = { | ||
key: "referred-history"; | ||
}; |
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,11 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
export function useMounted() { | ||
const [mounted, setMounted] = useState(false); | ||
|
||
useEffect(() => { | ||
setMounted(true); | ||
}, []); | ||
|
||
return mounted; | ||
} |
Oops, something went wrong.