Skip to content

Commit

Permalink
feat: mApp in sdk react and react-signin (#26)
Browse files Browse the repository at this point in the history
* feat: mApp in sdk react and react-signin

* feat: tests

* fix action

* fix action

* fix action
  • Loading branch information
HadiKhai authored Sep 20, 2024
1 parent 2488ac6 commit 57d5d48
Show file tree
Hide file tree
Showing 57 changed files with 1,064 additions and 507 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ jobs:
- run: npx nx affected -t lint
- name: Run Tests
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PROVIDER_URL: ${{ secrets.PROVIDER_URL }}
VALID_SUBNAME: ${{ secrets.VALID_SUBNAME }}
JUSTANAME_ENVIRONMENT: ${{ secrets.JUSTANAME_ENVIRONMENT }}
JUSTANAME_TEST_API_KEY: ${{ secrets.JUSTANAME_TEST_API_KEY }}
JUSTANAME_DEV: ${{ secrets.JUSTANAME_DEV }}
ENS_DOMAIN: ${{ secrets.ENS_DOMAIN }}
SDK_JUSTANAME_ENVIRONMENT: ${{ secrets.SDK_JUSTANAME_ENVIRONMENT }}
SDK_JUSTANAME_TEST_API_KEY: ${{ secrets.SDK_JUSTANAME_TEST_API_KEY }}
SDK_MAPP_PRIVATE_KEY: ${{ secrets.SDK_MAPP_PRIVATE_KEY }}
SDK_PROVIDER_URL: ${{ secrets.SDK_PROVIDER_URL }}
SDK_ENS_DOMAIN: ${{ secrets.SDK_ENS_DOMAIN }}
SDK_MAPP: ${{ secrets.SDK_MAPP }}
SIWENS_PRIVATE_KEY: ${{ secrets.SIWENS_PRIVATE_KEY }}
SIWENS_PROVIDER_URL: ${{ secrets.SIWENS_PROVIDER_URL }}
SIWENS_VALID_ENS: ${{ secrets.SIWENS_VALID_ENS }}
run: npx nx affected -t test --configuration=ci --passWithNoTests --exclude=justaname-mono-sdk
- run: npx nx affected -t build
16 changes: 9 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ jobs:
- name: Build and Test
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PROVIDER_URL: ${{ secrets.PROVIDER_URL }}
VALID_SUBNAME: ${{ secrets.VALID_SUBNAME }}
JUSTANAME_ENVIRONMENT: ${{ secrets.JUSTANAME_ENVIRONMENT }}
JUSTANAME_TEST_API_KEY: ${{ secrets.JUSTANAME_TEST_API_KEY }}
JUSTANAME_DEV: ${{ secrets.JUSTANAME_DEV }}
ENS_DOMAIN: ${{ secrets.ENS_DOMAIN }}
SDK_JUSTANAME_ENVIRONMENT: ${{ secrets.SDK_JUSTANAME_ENVIRONMENT }}
SDK_JUSTANAME_TEST_API_KEY: ${{ secrets.SDK_JUSTANAME_TEST_API_KEY }}
SDK_MAPP_PRIVATE_KEY: ${{ secrets.SDK_MAPP_PRIVATE_KEY }}
SDK_PROVIDER_URL: ${{ secrets.SDK_PROVIDER_URL }}
SDK_ENS_DOMAIN: ${{ secrets.SDK_ENS_DOMAIN }}
SDK_MAPP: ${{ secrets.SDK_MAPP }}
SIWENS_PRIVATE_KEY: ${{ secrets.SIWENS_PRIVATE_KEY }}
SIWENS_PROVIDER_URL: ${{ secrets.SIWENS_PROVIDER_URL }}
SIWENS_VALID_ENS: ${{ secrets.SIWENS_VALID_ENS }}
run: |
npx nx affected -t lint
npx nx affected -t test --configuration=ci --passWithNoTests --exclude=justaname-mono-sdk
Expand Down
6 changes: 5 additions & 1 deletion apps/express-trial/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
"development": {},
"production": {}
},
"dependsOn": ["lint"]
"dependsOn": ["lint",
{
"projects": ["@justaname.id/sdk"],
"target": "build"
}]
}
},
"tags": []
Expand Down
8 changes: 4 additions & 4 deletions apps/react-trial/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SIWJProvider, SIWJProviderConfig } from '@justaname.id/react-signin'
import { SIWENSProvider, SIWENSProviderConfig } from '@justaname.id/react-signin'
import '@rainbow-me/rainbowkit/styles.css';
import {
getDefaultConfig,
Expand All @@ -17,7 +17,7 @@ import { ChainId } from '@justaname.id/sdk';

const queryClient = new QueryClient();

const JustaNameConfig: SIWJProviderConfig = {
const JustaNameConfig: SIWENSProviderConfig = {
config: {
chainId: parseInt(import.meta.env.VITE_APP_CHAIN_ID) as ChainId,
origin: import.meta.env.VITE_APP_ORIGIN,
Expand All @@ -41,9 +41,9 @@ export function App() {
return (
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
<SIWJProvider config={JustaNameConfig} >
<SIWENSProvider config={JustaNameConfig} >
<Home />
</SIWJProvider>
</SIWENSProvider>
</QueryClientProvider>
</WagmiProvider>
);
Expand Down
16 changes: 8 additions & 8 deletions apps/with-privy/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SIWJProvider, SIWJProviderConfig } from '@justaname.id/react-signin'
import { SIWENSProvider, SIWENSProviderConfig } from '@justaname.id/react-signin'
import '@rainbow-me/rainbowkit/styles.css';
import { http } from 'wagmi';
import {
Expand All @@ -12,11 +12,11 @@ import {
import { ChainId } from '@justaname.id/sdk';
import { PrivyProvider, usePrivy } from '@privy-io/react-auth';
import {createConfig, WagmiProvider} from '@privy-io/wagmi';
import { useSubnameSession } from '@justaname.id/react';
import { useEnsAuth } from '@justaname.id/react';

const queryClient = new QueryClient();

const JustaNameConfig: SIWJProviderConfig = {
const JustaNameConfig: SIWENSProviderConfig = {
config: {
chainId: parseInt(import.meta.env.VITE_APP_CHAIN_ID) as ChainId,
origin: import.meta.env.VITE_APP_ORIGIN,
Expand All @@ -31,7 +31,7 @@ const JustaNameConfig: SIWJProviderConfig = {

const Connect = () => {
const { ready, authenticated, user, login, logout } = usePrivy();
const { subnameSession} = useSubnameSession();
const { connectedEns} = useEnsAuth();
if (!ready) {
return null;
}
Expand All @@ -57,10 +57,10 @@ const Connect = () => {
<button onClick={login} style={{padding: "12px", backgroundColor: "#069478", color: "#FFF", border: "none", borderRadius: "6px" }}>Log In</button>
)}
{
subnameSession && <div>
connectedEns && <div>
<textarea
readOnly
value={JSON.stringify(subnameSession, null, 2)}
value={JSON.stringify(connectedEns, null, 2)}
style={{ width: "600px", height: "250px", borderRadius: "6px" }}
/>
</div>
Expand Down Expand Up @@ -97,9 +97,9 @@ export function App() {
>
<QueryClientProvider client={queryClient}>
<WagmiProvider config={config}>
<SIWJProvider config={JustaNameConfig} >
<SIWENSProvider config={JustaNameConfig} >
<Connect />
</SIWJProvider>
</SIWENSProvider>
</WagmiProvider>
</QueryClientProvider>
</PrivyProvider>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { A, Flex, JustaNameLogoIcon, SPAN } from '@justaname.id/react-ui';

export const Footer = () => {
return(
<Flex
align={'center'}
justify={'space-between'}
style={{
padding: '10px 20px',
background: 'var(--justaname-foreground-color-4)',
borderRadius: ' 0 0 16px 16px'
}}
>
<Flex
justify={'center'}
align={'center'}
style={{
height: '19px'
}}
>
<SPAN
style={{
fontWeight: '700',
fontSize: '12px'
}}
>
Powered by <A
style={{
color: 'var(--justaname-primary-color)',
fontWeight: '700',
fontSize: '12px'

}}
href="https://justaname.id" target="_blank" rel="noreferrer">justaname.id</A>
</SPAN>

</Flex>
<JustaNameLogoIcon />
</Flex>
)
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './SelectSubnameItem';
export * from './Loading';
export * from './Loading';
export * from './Footer';
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import { FC, Fragment, useEffect, useMemo } from 'react';
import { useAddMAppPermission, useEnsAuth, useIsMAppEnabled, useRecords } from '@justaname.id/react';
import { Badge, Button, CloseIcon, Dialog, DialogContent, DialogTitle, Flex, H2, P } from '@justaname.id/react-ui';
import { Footer } from '../../components';
import { isParseable } from '../../utils';
import { LoadingDialog } from '../LoadingDialog';

export interface MAppDialogProps {
mApp: string;
open: boolean;
handleOpenDialog: (open: boolean) => void;
}

export const MAppDialog: FC<MAppDialogProps> = ({
mApp,
open,
handleOpenDialog
}) => {
const { connectedEns, isLoggedIn, isEnsAuthPending } = useEnsAuth();
const { records , isRecordsPending} = useRecords({
fullName: mApp || ''
});
const { isMAppEnabled, refetchIsMAppEnabled , isMAppEnabledPending } = useIsMAppEnabled({
subname: connectedEns?.ens || '',
mApp
});
const { addMAppPermission, isAddMAppPermissionPending } = useAddMAppPermission({
mApp
});

const mAppDescription = useMemo(() => {
return records?.texts?.find((text) => text.key === `mApp_description`)?.value;
}, [records]);

const mAppPermissions = useMemo((): string[] => {
console.log(records)
if (!records) {
return [];
}

const permissions = records?.texts?.find((text) => text.key === `mApp_permissions`)?.value;
if (!permissions) {
return [];
}

if (!isParseable(permissions)) {
return [];
}

const parsedPermissions = JSON.parse(permissions) as string[];
if (!Array.isArray(parsedPermissions)) {
return [];
}

return parsedPermissions;
}, [records]);

console.log(isMAppEnabled, open)
useEffect(() => {
if(isLoggedIn){

if(isMAppEnabledPending || isMAppEnabled === undefined){
return
}

handleOpenDialog(!isMAppEnabled)
}
else{
handleOpenDialog(false)
}
}, [isMAppEnabled, isLoggedIn, isMAppEnabledPending])

if (( isEnsAuthPending || isRecordsPending || isMAppEnabledPending) && open) {
return <LoadingDialog open={true} />
}

return (
<Dialog open={open}>
<div style={{
display: 'hidden'
}}>
<DialogTitle>

</DialogTitle>
</div>
<DialogContent style={{
padding: 0,
maxWidth: '500px',
transition: 'all 0.4 ease-in-out'
}}>
<Flex
style={{
padding: '0px 0 0 0',
borderRadius: '16px',
background: 'var(--justaname-foreground-color-4)'
}}
direction={'column'}
>
<Flex
style={{
padding: '40px 20px 20px 20px',
// border: "1px solid var(--justaname-input-border-color)",
borderRadius: '16px',
background: 'var(--justaname-background-color)',
gap: '20px',
display: 'flex',
flexDirection: 'column',
maxWidth: '500px'
}}
>
<Flex
justify="space-between"
direction="row"
gap="10px"
>
<Badge>
{connectedEns?.ens}
</Badge>

<CloseIcon
style={{
cursor: 'pointer'
}}
onClick={() => handleOpenDialog(false)}
/>
</Flex>

<Flex
justify="space-between"
direction="column"
gap="10px"
>
<H2>
Authorise {mApp} mApp
</H2>
</Flex>

<Flex
>
<P>
{mAppDescription}
</P>
</Flex>

<Flex
direction={"column"}
gap={"15px"}
>

{
mAppPermissions.map((permission, index) => {
return (<Fragment key={'permission_'+index}>
<Flex
direction={"column"}
gap={"5px"}
style={{
padding:"10px",
borderRadius:"16px",
border:"1px solid var(--justaname-foreground-color-4)"
}}
>

<P>
Permission
</P>

<P>
{permission}
</P>
</Flex>
</Fragment>
)
})
}
</Flex>

<Button
style={{
width:'100%',
}}
size="lg"
loading={isAddMAppPermissionPending}
onClick={() => {
addMAppPermission({
subname: connectedEns?.ens || '',
}).then(() => {
handleOpenDialog(false);
refetchIsMAppEnabled();
})
}}
>
Authorise
</Button>
</Flex>


<Footer />
</Flex>
</DialogContent>
</Dialog>
);
};
Loading

0 comments on commit 57d5d48

Please sign in to comment.