Skip to content

Commit

Permalink
Merge pull request #555 from eco-stake/minor-fixes
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
tombeynon authored Jul 11, 2022
2 parents 24e802b + a03d6a8 commit 19cd98b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
14 changes: 9 additions & 5 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class App extends React.Component {
} else if (this.props.network !== prevProps.network) {
this.setState({ balance: undefined, address: undefined, wallet: undefined, grants: undefined })
this.connect()
}else if(this.state.address !== prevState.address){
}else if(this.state.address !== prevState.address && prevState.address){
this.setState({ balance: undefined, grants: undefined })
this.getBalance()
this.getGrants()
Expand Down Expand Up @@ -190,8 +190,9 @@ class App extends React.Component {
error: false
})
this.getBalance()
this.getGrants()
this.refreshInterval();
this.getGrants().then(() => {
this.refreshInterval();
})
} catch (e) {
console.log(e)
return this.setState({
Expand Down Expand Up @@ -373,7 +374,9 @@ class App extends React.Component {
return true
}
this.setState((state, props) => {
const granterGrants = state.grants?.granter ? state.grants.granter.filter(filterGrant) : []
if(!state.grants) return {}

const granterGrants = state.grants.granter.filter(filterGrant)
granterGrants.push(grant)
return { grants: { ...state.grants, granter: granterGrants } }
})
Expand All @@ -394,6 +397,8 @@ class App extends React.Component {
return true;
}
this.setState((state, props) => {
if(!state.grants) return {}

const granterGrants = state.grants.granter.filter(filterGrant)
return { grants: { ...state.grants, granter: granterGrants } }
})
Expand Down Expand Up @@ -659,7 +664,6 @@ class App extends React.Component {
network={this.props.network}
address={this.state.address}
wallet={this.state.wallet}
grants={this.state.grants}
favouriteAddresses={this.state.favouriteAddresses[this.props.network.path] || []}
queryClient={this.props.queryClient}
stargateClient={this.state.stargateClient} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/Coins.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function Coins(props) {
function amount(coins, decimals){
if(props.inBaseDenom) return coins.amount

if (!decimals) {
if (decimals == null) {
decimals = 6
}
const prec = precision(coins, decimals)
Expand Down
2 changes: 1 addition & 1 deletion src/components/DelegateForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class DelegateForm extends React.Component {
this.props.stargateClient.simulate(this.props.address, messages).then(gas => {
const saveTxFeeNum = (this.props.redelegate || this.props.undelegate) ? 0 : 10
const gasPrice = this.props.stargateClient.getFee(gas).amount[0].amount
const decimals = pow(10, this.props.network.decimals || 6)
const decimals = pow(10, this.props.network.decimals)
const amount = divide(subtract(this.props.availableBalance.amount, multiply(gasPrice, saveTxFeeNum)), decimals)

this.setState({amount: amount > 0 ? amount : 0})
Expand Down
25 changes: 11 additions & 14 deletions src/components/Governance.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Proposal from '../utils/Proposal.mjs';
import Vote from '../utils/Vote.mjs';

function Governance(props) {
const { address, wallet, network, grants } = props
const { address, wallet, network } = props
const [showModal, setShowModal] = useState()
const [proposal, setProposal] = useState()
const [proposals, setProposals] = useState()
Expand Down Expand Up @@ -82,21 +82,20 @@ function Governance(props) {
if(!props.queryClient) return
const { clearExisting } = opts || {}

props.queryClient.getProposals().then(async (proposals) => {
proposals = proposals.map(el => Proposal(el))
setProposals(sortProposals(proposals))
setTallies(proposals.reduce((sum, proposal) => {
try {
let newProposals = await props.queryClient.getProposals()
newProposals = newProposals.map(el => Proposal(el))
setProposals(sortProposals(newProposals))
setTallies(newProposals.reduce((sum, proposal) => {
if (!_.every(Object.values(proposal.final_tally_result), el => el === '0')) {
sum[proposal.proposal_id] = proposal.final_tally_result
}
return sum
}, {}))
},
(error) => {
if(!proposals || clearExisting) setProposals([])
setError(`Failed to load proposals: ${error.message}`);
}
)
} catch (error) {
if (!proposals || clearExisting) setProposals([])
setError(`Failed to load proposals: ${error.message}`);
}
}

async function getTallies(proposals) {
Expand All @@ -109,9 +108,7 @@ function Governance(props) {
if (proposal.isVoting && talliesInvalid) {
return props.queryClient.getProposalTally(proposal_id).then(result => {
return setTallies({ [proposal_id]: result.tally })
}).catch(error => { })
} else {
return setTallies({ [proposal_id]: result })
})
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/Chain.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Chain = async (data, directory) => {
authzSupport: data.authzSupport ?? chainData.params?.authz,
denom: data.denom || base.denom,
symbol: data.symbol || token.denom,
decimals: data.decimals || token.exponent || 6,
decimals: data.decimals || (token.exponent ?? 6),
image: data.image || (asset.logo_URIs && (asset.logo_URIs.png || asset.logo_URIs.svg)),
coinGeckoId: asset.coingecko_id,
chainData,
Expand Down

0 comments on commit 19cd98b

Please sign in to comment.