-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
997dddf
commit ce9ef31
Showing
7 changed files
with
129 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
import { Button } from '@app/components/elements/Button'; | ||
import { Typography } from '@app/components/elements/Typography'; | ||
import { | ||
SettingsGroupContent, | ||
SettingsGroupTitle, | ||
SettingsGroupWrapper, | ||
} from '@app/containers/Settings/components/SettingsGroup.styles'; | ||
import { useAirdropStore } from '@app/store/useAirdropStore'; | ||
import { useAppConfigStore } from '@app/store/useAppConfigStore'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export default function AirdropLogout() { | ||
const { t } = useTranslation(['settings'], { useSuspense: false }); | ||
|
||
const airdropUIEnabled = useAppConfigStore((s) => s.airdrop_ui_enabled); | ||
const logout = useAirdropStore((state) => state.logout); | ||
const { userDetails } = useAirdropStore(); | ||
|
||
if (!airdropUIEnabled || !userDetails) return null; | ||
return ( | ||
<div style={{ maxWidth: 'fit-content', marginLeft: 'auto', padding: '20px' }}> | ||
<Button color="error" variant="text" size="medium" onClick={logout}> | ||
Disconnect from Airdrop | ||
</Button> | ||
</div> | ||
<SettingsGroupWrapper> | ||
<SettingsGroupTitle> | ||
<Typography variant="h6">{t('connection')}</Typography> | ||
</SettingsGroupTitle> | ||
<SettingsGroupContent> | ||
<div style={{ maxWidth: 'fit-content', marginLeft: 'auto', padding: '20px' }}> | ||
<Button color="error" variant="text" size="medium" onClick={logout}> | ||
{t('disconnect')} | ||
</Button> | ||
</div> | ||
</SettingsGroupContent> | ||
</SettingsGroupWrapper> | ||
); | ||
} |
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,9 @@ | ||
import { useAirdropStore } from '@app/store/useAirdropStore'; | ||
import AirdropLogout from '../Airdrop/Settings/Logout'; | ||
import { ApplyInviteCode } from './sections/airdrop/ApplyInviteCode'; | ||
|
||
export const AirdropSettings = () => { | ||
const { authUuid } = useAirdropStore(); | ||
|
||
return <>{authUuid ? <AirdropLogout /> : <ApplyInviteCode />}</>; | ||
}; |
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
90 changes: 90 additions & 0 deletions
90
src/containers/Settings/sections/airdrop/ApplyInviteCode.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,90 @@ | ||
import { SettingsGroupContent, SettingsGroupTitle, SettingsGroupWrapper } from '../../components/SettingsGroup.styles'; | ||
import { Typography } from '@app/components/elements/Typography'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { Input } from '@app/components/elements/inputs/Input'; | ||
import { Button } from '@app/components/elements/Button'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { useAirdropStore } from '@app/store/useAirdropStore'; | ||
import { Stack } from '@app/components/elements/Stack'; | ||
import { useAppConfigStore } from '@app/store/useAppConfigStore'; | ||
|
||
export const ApplyInviteCode = () => { | ||
const { t } = useTranslation(['settings'], { useSuspense: false }); | ||
const setAllowTelemetry = useAppConfigStore((s) => s.setAllowTelemetry); | ||
|
||
const [claimCode, setClaimCode] = useState(''); | ||
|
||
const { authUuid, setAuthUuid, setAirdropTokens, setUserPoints, backendInMemoryConfig } = useAirdropStore(); | ||
|
||
const handleAuth = useCallback( | ||
(code?: string) => { | ||
const token = uuidv4(); | ||
if (backendInMemoryConfig?.airdropTwitterAuthUrl) { | ||
setAuthUuid(token); | ||
setAllowTelemetry(true); | ||
|
||
open( | ||
`${backendInMemoryConfig?.airdropTwitterAuthUrl}?tauri=${token}${code ? `&universeReferral=${code}` : ''}` | ||
); | ||
} | ||
}, | ||
[backendInMemoryConfig?.airdropTwitterAuthUrl, setAllowTelemetry, setAuthUuid] | ||
); | ||
|
||
useEffect(() => { | ||
if (authUuid && backendInMemoryConfig?.airdropApiUrl) { | ||
const interval = setInterval(() => { | ||
if (authUuid) { | ||
fetch(`${backendInMemoryConfig?.airdropApiUrl}/auth/twitter/get-token/${authUuid}`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}) | ||
.then((response) => response.json()) | ||
.then((data) => { | ||
if (!data.error) { | ||
clearInterval(interval); | ||
setAirdropTokens(data); | ||
} | ||
}); | ||
} | ||
}, 1000); | ||
const timeout = setTimeout( | ||
() => { | ||
clearInterval(interval); | ||
setAuthUuid(''); | ||
}, | ||
1000 * 60 * 5 | ||
); | ||
|
||
return () => { | ||
clearInterval(interval); | ||
clearTimeout(timeout); | ||
}; | ||
} | ||
}, [authUuid, backendInMemoryConfig?.airdropApiUrl, setAirdropTokens, setAuthUuid, setUserPoints]); | ||
|
||
return ( | ||
<SettingsGroupWrapper> | ||
<SettingsGroupTitle> | ||
<Typography variant="h6">{t('inviteCode')}</Typography> | ||
</SettingsGroupTitle> | ||
<SettingsGroupContent> | ||
<Stack direction="row" gap={4} justifyContent="flex-start"> | ||
<Input | ||
name="apply-invite-code" | ||
patternType="text" | ||
value={claimCode} | ||
onChange={(event) => setClaimCode(event.target.value)} | ||
style={{ maxWidth: '20rem' }} | ||
></Input> | ||
<Button color="error" variant="text" size="medium" onClick={() => handleAuth(claimCode)}> | ||
{t('applyInviteCode')} | ||
</Button> | ||
</Stack> | ||
</SettingsGroupContent> | ||
</SettingsGroupWrapper> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const SETTINGS_TYPES = ['mining', 'general', 'wallet', 'experimental'] as const; | ||
export const SETTINGS_TYPES = ['mining', 'general', 'wallet', 'experimental', 'airdrop'] as const; | ||
type SettingsTuple = typeof SETTINGS_TYPES; | ||
export type SettingsType = SettingsTuple[number]; |