-
Notifications
You must be signed in to change notification settings - Fork 56
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 #1452 from ecency/feat/claim-account-credit
Added claiming to RC modal
- Loading branch information
Showing
9 changed files
with
443 additions
and
184 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
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,34 @@ | ||
@import "src/style/vars_mixins"; | ||
|
||
.claim-credit { | ||
&-title { | ||
display: flex; | ||
align-items: center; | ||
gap: 0.5rem; | ||
|
||
&-back { | ||
cursor: pointer; | ||
|
||
svg { | ||
width: 1rem; | ||
height: 1rem; | ||
} | ||
} | ||
|
||
@include themify(night) { | ||
color: $gray-400; | ||
} | ||
} | ||
|
||
.key-or-hot { | ||
padding: 0; | ||
margin: 1rem 0 0; | ||
|
||
.input-group { | ||
svg { | ||
width: 1rem; | ||
height: 1rem; | ||
} | ||
} | ||
} | ||
} |
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,100 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { Button } from "react-bootstrap"; | ||
import { arrowLeftSvg } from "../../img/svg"; | ||
import "./index.scss"; | ||
import { FullAccount } from "../../store/accounts/types"; | ||
import { useAccountClaiming } from "../../api/mutations"; | ||
import { _t } from "../../i18n"; | ||
import KeyOrHot from "../key-or-hot"; | ||
import { useMappedStore } from "../../store/use-mapped-store"; | ||
import { claimAccountByHiveSigner } from "../../api/operations"; | ||
|
||
interface Props { | ||
account: FullAccount; | ||
claimAccountAmount: number; | ||
} | ||
|
||
const ClaimAccountCredit = ({ account, claimAccountAmount }: Props) => { | ||
const { global, activeUser, addAccount } = useMappedStore(); | ||
const { | ||
mutateAsync: claimAccount, | ||
isLoading, | ||
error, | ||
isSuccess, | ||
reset | ||
} = useAccountClaiming(account); | ||
|
||
const [key, setKey] = useState(""); | ||
const [isKeySetting, setIsKeySetting] = useState(false); | ||
|
||
useEffect(() => { | ||
if (isSuccess) { | ||
addAccount({ | ||
...account, | ||
pending_claimed_accounts: 0 | ||
}); | ||
} | ||
}, [isSuccess]); | ||
|
||
return ( | ||
<div className="claim-credit"> | ||
<div className="claim-credit-title"> | ||
{isKeySetting ? ( | ||
<div | ||
className="claim-credit-title-back" | ||
onClick={() => { | ||
setIsKeySetting(false); | ||
reset(); | ||
}} | ||
> | ||
{arrowLeftSvg} | ||
</div> | ||
) : ( | ||
<></> | ||
)} | ||
{_t("rc-info.claim-accounts")} | ||
<span className="text-primary">{claimAccountAmount}</span> | ||
</div> | ||
{!isSuccess && | ||
!isKeySetting && | ||
claimAccountAmount > 0 && | ||
activeUser?.username === account.name ? ( | ||
<Button size="sm" onClick={() => setIsKeySetting(true)}> | ||
{_t("rc-info.claim")} | ||
</Button> | ||
) : ( | ||
<></> | ||
)} | ||
{isSuccess ? ( | ||
<small className="text-success my-3 d-block">{_t("rc-info.successfully-claimed")}</small> | ||
) : ( | ||
<></> | ||
)} | ||
{error ? ( | ||
<small className="d-block text-danger my-3">{(error as Error)?.message}</small> | ||
) : ( | ||
<></> | ||
)} | ||
{isKeySetting && !isSuccess ? ( | ||
<KeyOrHot | ||
inProgress={isLoading} | ||
signingKey={key} | ||
setSigningKey={(k) => setKey(k)} | ||
global={global} | ||
activeUser={activeUser} | ||
onKey={(key) => claimAccount({ key })} | ||
onHot={() => claimAccountByHiveSigner(account)} | ||
onKc={() => | ||
claimAccount({ | ||
isKeychain: true | ||
}) | ||
} | ||
/> | ||
) : ( | ||
<></> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ClaimAccountCredit; |
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.