-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add manual claims * fix routing * fix application routes * fix: add navigation * some fixes --------- Co-authored-by: ridel1e <[email protected]>
- Loading branch information
1 parent
d7322e3
commit 7c65ddd
Showing
7 changed files
with
455 additions
and
167 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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
import { | ||
Alert, | ||
Box, | ||
Button, | ||
CopyOutlined, | ||
Empty, | ||
Flex, | ||
Form, | ||
Input, | ||
message, | ||
Typography, | ||
useForm, | ||
} from '@ergolabs/ui-kit'; | ||
import { t, Trans } from '@lingui/macro'; | ||
import { FC, useState } from 'react'; | ||
import CopyToClipboard from 'react-copy-to-clipboard'; | ||
|
||
import { AssetIcon } from '../../components/AssetIcon/AssetIcon.tsx'; | ||
import { Page } from '../../components/Page/Page.tsx'; | ||
import { | ||
IspoRewardsData, | ||
requestIspoRewards, | ||
} from '../../network/cardano/api/rewards/rewards.ts'; | ||
|
||
const REWARDS_ADDRESS = | ||
'addr1vx3vcluw7qtulynhzsy4prfdmnjth8w52ejg2qeclsz7argu26gcf'; | ||
|
||
interface IspoForm { | ||
address?: string; | ||
} | ||
|
||
interface IspoRewardsViewProps { | ||
data: IspoRewardsData; | ||
} | ||
|
||
const IspoRewardsView: FC<IspoRewardsViewProps> = ({ data }) => { | ||
return ( | ||
<Box borderRadius="l" bordered padding={3}> | ||
<Flex col> | ||
<Flex.Item marginBottom={2} justify="space-between"> | ||
<Typography.Title level={5}> | ||
<Trans>Available</Trans> | ||
</Typography.Title> | ||
<Flex align="center"> | ||
<Flex.Item marginRight={1}> | ||
<AssetIcon asset={data.available.asset} /> | ||
</Flex.Item> | ||
|
||
<Typography.Body size="large" strong> | ||
{data.available.toString()} {data.available.asset.ticker} | ||
</Typography.Body> | ||
</Flex> | ||
</Flex.Item> | ||
|
||
<Flex.Item justify="space-between"> | ||
<Typography.Title level={5}> | ||
<Trans>Claimed</Trans> | ||
</Typography.Title> | ||
<Flex align="center"> | ||
<Flex.Item marginRight={1}> | ||
<AssetIcon asset={data.received.asset} /> | ||
</Flex.Item> | ||
|
||
<Typography.Body size="large" strong> | ||
{data.received.toString()} {data.received.asset.ticker} | ||
</Typography.Body> | ||
</Flex> | ||
</Flex.Item> | ||
</Flex> | ||
</Box> | ||
); | ||
}; | ||
|
||
const ClaimIspoRewards: FC<{ data: IspoRewardsData }> = ({ data }) => { | ||
return ( | ||
<Box borderRadius="l" bordered padding={3}> | ||
<Flex col> | ||
{data.available.amount > 0n ? ( | ||
<> | ||
<Flex.Item marginBottom={2}> | ||
<Typography.Body strong> | ||
<Trans> | ||
Complete the claiming process by sending{' '} | ||
<span style={{ color: 'var(--spectrum-warning-color)' }}> | ||
5 ADA | ||
</span>{' '} | ||
in ONE transaction to the address below: | ||
</Trans> | ||
</Typography.Body> | ||
</Flex.Item> | ||
<Flex.Item marginBottom={2}> | ||
<CopyToClipboard | ||
text={REWARDS_ADDRESS} | ||
onCopy={() => message.success(t`Address copied!`)} | ||
> | ||
<Typography.Link onClick={(e) => e.stopPropagation()}> | ||
<CopyOutlined style={{ marginRight: '4px' }} /> | ||
{REWARDS_ADDRESS} | ||
</Typography.Link> | ||
</CopyToClipboard> | ||
</Flex.Item> | ||
<Flex.Item marginBottom={2}> | ||
<Alert | ||
type="warning" | ||
showIcon | ||
message={t`Only send ADA from the wallet that owns the provided stake or payment address. Otherwise your request won't be processed. If you accidentally made something wrong, contact support`} | ||
/> | ||
</Flex.Item> | ||
<Flex.Item> | ||
<Alert | ||
type="info" | ||
showIcon | ||
message={t`All ADA will be returned to you except ~0.4 ADA which will be spent on the network fee.`} | ||
/> | ||
</Flex.Item> | ||
</> | ||
) : ( | ||
<Flex.Item> | ||
<Alert | ||
type="info" | ||
showIcon | ||
message={t`No available rewards for now. Come back next epoch!`} | ||
/> | ||
</Flex.Item> | ||
)} | ||
</Flex> | ||
</Box> | ||
); | ||
}; | ||
|
||
const renderRewards = (data?: IspoRewardsData) => { | ||
if (!data) { | ||
return <></>; | ||
} | ||
|
||
if (data.received.amount <= 0n && data.available.amount <= 0n) { | ||
return ( | ||
<Flex col align="center"> | ||
<Empty /> | ||
<Typography.Body strong> | ||
<Trans>No rewards found</Trans> | ||
</Typography.Body> | ||
</Flex> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<Flex.Item marginBottom={2}> | ||
<IspoRewardsView data={data} /> | ||
</Flex.Item> | ||
<Flex.Item> | ||
<ClaimIspoRewards data={data} /> | ||
</Flex.Item> | ||
</> | ||
); | ||
}; | ||
|
||
export const IspoRewards = () => { | ||
const [data, setData] = useState<IspoRewardsData | undefined>(undefined); | ||
const form = useForm<IspoForm>({ | ||
address: undefined, | ||
}); | ||
|
||
return ( | ||
<Page | ||
withBackButton | ||
backTo="../../../rewards" | ||
width={600} | ||
title="Claim ISPO rewards" | ||
> | ||
<Flex col> | ||
<Flex.Item marginBottom={data ? 2 : 0}> | ||
<Form | ||
form={form} | ||
onSubmit={({ value: { address } }) => { | ||
if (address) { | ||
requestIspoRewards(address).then((data) => { | ||
setData(data); | ||
}); | ||
} | ||
}} | ||
> | ||
<Form.Listener<IspoForm>> | ||
{({ value }) => { | ||
return ( | ||
<Input | ||
size="middle" | ||
placeholder={t`Enter your stake or payment address`} | ||
value={value.address} | ||
onChange={({ target }) => { | ||
form.patchValue({ address: target.value }); | ||
}} | ||
/> | ||
); | ||
}} | ||
</Form.Listener> | ||
<Button | ||
style={{ marginTop: '8px' }} | ||
htmlType="submit" | ||
type="primary" | ||
> | ||
Check My Reward | ||
</Button> | ||
</Form> | ||
</Flex.Item> | ||
|
||
{renderRewards(data)} | ||
</Flex> | ||
</Page> | ||
); | ||
}; |
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
Oops, something went wrong.