Skip to content

Commit

Permalink
feat: token symbol display done
Browse files Browse the repository at this point in the history
  • Loading branch information
MdTeach committed Oct 11, 2023
1 parent 1448add commit ba4ce13
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ const AddCriteria = ({
contract: `${selectedChain}:${contract}`,
amount: quantity.value,
comparison: dropdownQuantityRangeValues[quantity.range].value,
decimals: 18,
decimals: category === CATEGORY.ERC20 ? decimals : undefined,
token:unit
};
} else if (category === CATEGORY.INVITE) {
const _inviteRoles = [];
Expand Down Expand Up @@ -410,6 +411,15 @@ const AddCriteria = ({
)
);

if(pushData.token){
setUnit(pushData.token)
}

if(pushData.decimals){
setDecimals(decimals)
}

// TODO: make helper function for this
const contractAndChain: string[] = (
pushData.contract || 'eip155:1:0x'
).split(':');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ThemeContext } from '../theme/ThemeProvider';
import Dropdown, { DropdownValueType } from '../reusables/DropDown';
import { ConditionArray, ConditionData, IChatTheme } from '../exportedTypes';
import { useClickAway } from '../../../hooks';
import { CATEGORY, CRITERIA_TYPE, CriteriaType, TOKEN_NFT_COMPARISION, TokenNftComparision } from '../types';
import { CATEGORY, CRITERIA_TYPE, CriteriaType, PushData, TOKEN_NFT_COMPARISION, TokenNftComparision } from '../types';

import EditSvg from '../../../icons/EditSvg.svg';
import RemoveSvg from '../../../icons/RemoveSvg.svg';
Expand Down Expand Up @@ -94,6 +94,19 @@ const CriteriaSection = ({ criteria }: { criteria: ConditionData }) => {
return (GUILD_COMPARISON_OPTIONS.find(option => option.value === criteria?.data?.['comparison']))?.heading;

}

const getTokenSymbol = (conditionData:ConditionData)=>{
if(conditionData.data){
const data:PushData = conditionData.data;
if(data.token){
// TODO truncate the token symbol
return data.token
}
}

return conditionData.category
}

return (
<Section gap="8px">
<Span
Expand All @@ -112,7 +125,7 @@ const CriteriaSection = ({ criteria }: { criteria: ConditionData }) => {
{getTokenNftComparisionLabel()}{' '}
</Span>
{/* need to fetch token symbol */}
{criteria?.data?.['amount']} {criteria.category}
{criteria?.data?.['amount']} {getTokenSymbol(criteria)}
</Span>
)}
{criteria.category === CATEGORY.INVITE && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const validateTokenData = async (condition:Rule):Promise<CriteriaValidationError
const _eip155Format = _contract.split(":")

if(_eip155Format.length !==3){
return {tokenError:"Invalid contract"}
return {tokenError:"Invalid contract address"}
}

const [chainId, address] = [parseInt(_eip155Format[1]), _eip155Format[2]]
Expand All @@ -99,17 +99,14 @@ const validationCriteria = async (condition: Rule):Promise<CriteriaValidationEr
{
return validateGUILDData(condition);
}else{
// PUSH type
if(condition.category === CATEGORY.INVITE){
// validate invite
return {}
}else if (condition.category === CATEGORY.CustomEndpoint){
// custim role
return {}
}else{
// token verifcation
return validateTokenData(condition)
}
}

return {};
}
export { handleDefineCondition ,validationCriteria};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface PushData {
inviterRoles?: string[];
comparison?:string;
url?: string;
token?:string;
}

export interface GuildData {
Expand Down

0 comments on commit ba4ce13

Please sign in to comment.