-
Notifications
You must be signed in to change notification settings - Fork 65
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 #2334 from DistributedCollective/development
Perpetuals - remove whitelist (#2332)
- Loading branch information
Showing
8 changed files
with
155 additions
and
5 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
107 changes: 107 additions & 0 deletions
107
src/app/pages/PerpetualPage/components/CompetitionPage/components/RegisterDialog/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,107 @@ | ||
import React, { useState, useCallback } from 'react'; | ||
import axios from 'axios'; | ||
import { Checkbox } from '@blueprintjs/core'; | ||
|
||
import { walletService } from '@sovryn/react-wallet'; | ||
import { Dialog, DialogSize } from 'app/containers/Dialog'; | ||
import { Input } from 'app/components/Form/Input'; | ||
import { FormGroup } from 'app/components/Form/FormGroup'; | ||
import { DialogButton } from 'app/components/Form/DialogButton'; | ||
import { DummyField } from 'app/components/DummyField'; | ||
import { useIsConnected, useAccount } from 'app/hooks/useAccount'; | ||
import { currentChainId, notificationServiceUrl } from 'utils/classifiers'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { translations } from 'locales/i18n'; | ||
|
||
const SIGNED_MSG_BASE = 'Login to backend on: %%'; | ||
const baseUrl = notificationServiceUrl[currentChainId]; | ||
|
||
interface IRegisterDialogProps { | ||
isOpen: boolean; | ||
onClose: (success: boolean) => void; | ||
} | ||
|
||
export const RegisterDialog: React.FC<IRegisterDialogProps> = ({ | ||
isOpen, | ||
onClose, | ||
}) => { | ||
const account = useAccount(); | ||
const connected = useIsConnected(); | ||
const { t } = useTranslation(); | ||
|
||
const [pseudonym, setPseudonym] = useState(''); | ||
const [termsChecked, setTermsChecked] = useState(false); | ||
|
||
const onSubmit = useCallback(() => { | ||
if (account) { | ||
const loginMessage = SIGNED_MSG_BASE.replace('%%', new Date().toString()); | ||
walletService.signMessage(loginMessage).then(res => | ||
axios | ||
.post(`${baseUrl}tradingCompetition/${account.toLowerCase()}`, { | ||
...(pseudonym.length ? { userName: pseudonym } : {}), | ||
message: loginMessage, | ||
signedMessage: res, | ||
}) | ||
.then(res => { | ||
if (res.status && res.status === 200) { | ||
setPseudonym(''); | ||
onClose(true); | ||
} | ||
}) | ||
.catch(e => { | ||
console.error(e); | ||
}), | ||
); | ||
} else { | ||
console.log('NO ACCOUNT'); | ||
} | ||
}, [onClose, account, pseudonym]); | ||
|
||
return ( | ||
<Dialog | ||
isOpen={isOpen} | ||
onClose={() => { | ||
setPseudonym(''); | ||
onClose(false); | ||
}} | ||
size={DialogSize.md} | ||
> | ||
<div className="tw-mx-auto"> | ||
<h1 className="tw-text-sov-white tw-text-center"> | ||
{t(translations.competitionPage.join.title)} | ||
</h1> | ||
|
||
<FormGroup | ||
label={t(translations.competitionPage.join.pseudonym)} | ||
className="tw-mb-6" | ||
> | ||
<Input | ||
value={pseudonym} | ||
onChange={setPseudonym} | ||
placeholder={t( | ||
translations.competitionPage.join.pseudonymPlaceholder, | ||
)} | ||
className="tw-max-w-full" | ||
/> | ||
</FormGroup> | ||
<FormGroup | ||
label={t(translations.competitionPage.join.wallet)} | ||
className="tw-mb-6" | ||
> | ||
<DummyField>{account}</DummyField> | ||
</FormGroup> | ||
|
||
<Checkbox | ||
checked={termsChecked} | ||
onChange={() => setTermsChecked(!termsChecked)} | ||
label={t(translations.competitionPage.join.conditions)} | ||
/> | ||
<DialogButton | ||
confirmLabel={t(translations.competitionPage.join.cta)} | ||
onConfirm={onSubmit} | ||
disabled={!termsChecked || !connected} | ||
/> | ||
</div> | ||
</Dialog> | ||
); | ||
}; |
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