-
Notifications
You must be signed in to change notification settings - Fork 21
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 #128 from DA0-DA0/staking-ui
Staking UI
- Loading branch information
Showing
10 changed files
with
391 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react' | ||
import TwitterLogo from 'components/TwitterLogo' | ||
import GitHubLogo from 'components/GitHubLogo' | ||
|
||
const POWERED_BY_URL = 'https://junonetwork.io' | ||
const TWITTER_URL = 'https://twitter.com/da0_da0' | ||
const GITHUB_URL = 'https://github.com/DA0-DA0' | ||
|
||
export default function Footer() { | ||
return ( | ||
<footer className="border-t w-full h-24 flex align-center justify-center flex-col"> | ||
<div className="flex items-center justify-center w-full"> | ||
Powered by{' '} | ||
<a className="pl-1 link link-primary link-hover" href={POWERED_BY_URL}> | ||
<div>Juno</div> | ||
</a> | ||
</div> | ||
<div className="flex items-center justify-center w-full"> | ||
<a href={TWITTER_URL}> | ||
<TwitterLogo /> | ||
</a> | ||
<a href={GITHUB_URL}> | ||
<GitHubLogo /> | ||
</a> | ||
</div> | ||
</footer> | ||
) | ||
} |
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,48 @@ | ||
import { useState, useEffect } from 'react' | ||
import { useSigningClient } from 'contexts/cosmwasm' | ||
import { BalanceResponse } from '@dao-dao/types/contracts/cw20-gov/balance_response' | ||
import { TokenInfoResponse } from '@dao-dao/types/contracts/cw20-gov/token_info_response' | ||
|
||
// Returns cw20 balance info for the connected wallet | ||
export function useCw20WalletBalance(contractAddress: string) { | ||
const [error, setError] = useState<Error | null>(null) | ||
const [loading, setLoading] = useState(false) | ||
const { walletAddress, signingClient } = useSigningClient() | ||
const [balance, setBalance] = useState<BalanceResponse | null>(null) | ||
const [tokenInfo, setTokenInfo] = useState<TokenInfoResponse | null>(null) | ||
|
||
useEffect(() => { | ||
if (walletAddress.length === 0 || !signingClient) { | ||
return | ||
} | ||
setLoading(true) | ||
Promise.all([ | ||
signingClient?.queryContractSmart(contractAddress, { | ||
balance: { | ||
address: walletAddress, | ||
}, | ||
}), | ||
signingClient.queryContractSmart(contractAddress, { | ||
token_info: {}, | ||
}), | ||
]) | ||
.then((values) => { | ||
const [balance, tokenInfo] = values | ||
setBalance(balance) | ||
setTokenInfo(tokenInfo) | ||
setLoading(false) | ||
}) | ||
.catch((e) => { | ||
setError(e.msg) | ||
setLoading(false) | ||
}) | ||
}, [contractAddress, signingClient, walletAddress]) | ||
|
||
return { | ||
walletAddress, | ||
loading, | ||
error, | ||
balance, | ||
tokenInfo, | ||
} | ||
} |
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,158 @@ | ||
import { useState, useEffect } from 'react' | ||
import { useSigningClient } from 'contexts/cosmwasm' | ||
import { defaultExecuteFee } from 'util/fee' | ||
|
||
// Returns staking info and methods for a cw20-stakable contract | ||
export function useStaking(contractAddress: string) { | ||
const { walletAddress, signingClient } = useSigningClient() | ||
const [error, setError] = useState('') | ||
const [loading, setLoading] = useState(false) | ||
|
||
const [stakedBalance, setStakedBalance] = useState({ balance: '0' }) | ||
const [claims, setClaims] = useState() | ||
const [delegation, setDelegation] = useState() | ||
const [totalStaked, setTotalStaked] = useState({ total: '0' }) | ||
|
||
useEffect(() => { | ||
if (walletAddress.length === 0 || !signingClient) { | ||
return | ||
} | ||
setLoading(true) | ||
Promise.all([ | ||
signingClient?.queryContractSmart(contractAddress, { | ||
staked_balance_at_height: { | ||
address: walletAddress, | ||
}, | ||
}), | ||
signingClient?.queryContractSmart(contractAddress, { | ||
claims: { | ||
address: walletAddress, | ||
}, | ||
}), | ||
signingClient?.queryContractSmart(contractAddress, { | ||
delegation: { | ||
address: walletAddress, | ||
}, | ||
}), | ||
signingClient?.queryContractSmart(contractAddress, { | ||
total_staked_at_height: {}, | ||
}), | ||
]) | ||
.then((values) => { | ||
const [stakedBalance, claims, delegation, totalStaked] = values | ||
setStakedBalance(stakedBalance) | ||
setClaims(claims) | ||
setTotalStaked(totalStaked) | ||
setDelegation(delegation) | ||
setLoading(false) | ||
}) | ||
.catch((e) => { | ||
setError(e.msg) | ||
setLoading(false) | ||
}) | ||
}, [contractAddress, signingClient, walletAddress]) | ||
|
||
const claim = async () => { | ||
setError('') | ||
await signingClient | ||
?.execute( | ||
walletAddress, | ||
contractAddress, | ||
{ | ||
claim: {}, | ||
}, | ||
defaultExecuteFee | ||
) | ||
.then((response) => { | ||
console.log(response) | ||
setLoading(false) | ||
}) | ||
.catch((err) => { | ||
setLoading(false) | ||
setError(err.message) | ||
}) | ||
} | ||
|
||
const delegateVotes = async (recipient: string) => { | ||
setError('') | ||
await signingClient | ||
?.execute( | ||
walletAddress, | ||
contractAddress, | ||
{ | ||
delegate_votes: { | ||
recipient, | ||
}, | ||
}, | ||
defaultExecuteFee | ||
) | ||
.then((response) => { | ||
console.log(response) | ||
setLoading(false) | ||
}) | ||
.catch((err) => { | ||
setLoading(false) | ||
setError(err.message) | ||
}) | ||
} | ||
|
||
const stake = async (amount: string) => { | ||
setError('') | ||
await signingClient | ||
?.execute( | ||
walletAddress, | ||
contractAddress, | ||
{ | ||
stake: { | ||
amount, | ||
}, | ||
}, | ||
defaultExecuteFee | ||
) | ||
.then((response) => { | ||
console.log(response) | ||
setLoading(false) | ||
}) | ||
.catch((err) => { | ||
setLoading(false) | ||
setError(err.message) | ||
}) | ||
} | ||
|
||
const unstake = async (amount: string) => { | ||
setError('') | ||
await signingClient | ||
?.execute( | ||
walletAddress, | ||
contractAddress, | ||
{ | ||
unstake: { | ||
amount, | ||
}, | ||
}, | ||
defaultExecuteFee | ||
) | ||
.then((response) => { | ||
console.log(response) | ||
setLoading(false) | ||
}) | ||
.catch((err) => { | ||
setLoading(false) | ||
setError(err.message) | ||
}) | ||
} | ||
|
||
return { | ||
walletAddress, | ||
loading, | ||
error, | ||
claim, | ||
claims, | ||
delegateVotes, | ||
delegation, | ||
stake, | ||
stakedBalance, | ||
totalStaked, | ||
unstake, | ||
} | ||
} |
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
Oops, something went wrong.
9575bfe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: