Skip to content

Commit

Permalink
Use native token decimals for reputation display
Browse files Browse the repository at this point in the history
  • Loading branch information
ceolson01 committed Mar 30, 2020
1 parent 3490aac commit 9594b33
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/modules/core/components/InfoPopover/MemberInfoPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import React, { useEffect } from 'react';
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';

import { DEFAULT_TOKEN_DECIMALS } from '~constants';
import Badge from '~core/Badge';
import Heading from '~core/Heading';
import Numeral from '~core/Numeral';
Expand All @@ -11,6 +10,7 @@ import {
useUserBadgesQuery,
useUserReputationQuery,
useColonyNativeTokenQuery,
useTokenInfoLazyQuery,
} from '~data/index';
import { Address } from '~types/index';

Expand Down Expand Up @@ -55,6 +55,18 @@ const MemberInfoPopover = ({ colonyAddress, domainId, user }: Props) => {
profile: { walletAddress },
} = user;

const {
data: nativeTokenAddressData,
loading: loadingNativeTokenAddress,
} = useColonyNativeTokenQuery({
variables: { address: colonyAddress },
});

const [
fetchTokenInfo,
{ data: tokenInfoData, loading: loadingTokenInfoData },
] = useTokenInfoLazyQuery();

const {
data: userReputationData,
loading: loadingUserReputation,
Expand All @@ -63,17 +75,19 @@ const MemberInfoPopover = ({ colonyAddress, domainId, user }: Props) => {
variables: { address: walletAddress, colonyAddress, domainId },
});

const {
data: nativeTokenData,
loading: loadingNativeToken,
} = useColonyNativeTokenQuery({
variables: { address: colonyAddress },
});

const { data } = useUserBadgesQuery({
variables: { address: walletAddress, colonyAddress },
});

useEffect(() => {
if (nativeTokenAddressData) {
const {
colony: { nativeTokenAddress },
} = nativeTokenAddressData;
fetchTokenInfo({ variables: { address: nativeTokenAddress } });
}
}, [fetchTokenInfo, nativeTokenAddressData]);

const completedLevels = data ? data.user.completedLevels : [];

return (
Expand All @@ -89,16 +103,18 @@ const MemberInfoPopover = ({ colonyAddress, domainId, user }: Props) => {
text={MSG.headingReputation}
/>
</div>
{userReputationData && nativeTokenData && (
{userReputationData && tokenInfoData && (
<Numeral
appearance={{ theme: 'blue', weight: 'medium' }}
value={userReputationData.userReputation}
unit={DEFAULT_TOKEN_DECIMALS}
unit={tokenInfoData.tokenInfo.decimals}
/>
)}
</div>
{(loadingUserReputation || loadingNativeToken) && <SpinnerLoader />}
{userReputationData && (
{(loadingUserReputation ||
loadingNativeTokenAddress ||
loadingTokenInfoData) && <SpinnerLoader />}
{userReputationData && tokenInfoData && (
<>
<FormattedMessage tagName="b" {...MSG.descriptionReputation} />
</>
Expand Down

0 comments on commit 9594b33

Please sign in to comment.