Skip to content

Commit

Permalink
Council menu infos & style
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkazu committed Apr 7, 2024
1 parent 1bbdad0 commit 6ca55b6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 62 deletions.
60 changes: 34 additions & 26 deletions fs-dapp_2.0/src/components/pages/Council.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Card, Col, Space } from 'antd';
import Identicon from '@polkadot/react-identicon';
import InfiniteScroll from "react-infinite-scroll-component";
import { Avatar, Divider, List, Skeleton } from "antd";
import { Button } from 'flowbite-react';
import { Button } from 'antd';


export default function Council() {
Expand All @@ -37,8 +37,8 @@ export default function Council() {

});
if(selectedProposal){
console.log(selectedAccount);
console.log(council_members);
console.log(selectedProposal.infos);
//console.log(council_members);
}
}

Expand All @@ -63,17 +63,8 @@ export default function Council() {
let referendum = Prop.sessionClosed.toString();
let hash = Prop.proposalHash.toString();
let infos = Prop.infos.toString();
console.log(Prop.infos.split(`:`)[1])

api.query.backgroundCouncil.voting(hash,(data:any)=>{
let data1 = data.toHuman();
if (data1 !== null) {
let yes = data1.ayes.length;
let no = data1.nays.length;
dispatch1({ type: 'SET_AYES', payload: yes });
dispatch1({ type: 'SET_NAY', payload: no });
}
})


let dtype:DataType={name:acc1.meta.name,role:r_session,address: Prop.accountId,status,referendum,hash,infos};
let prop0:Proposal={voter_id:selectedAccount,Referendum_account:acc1,session_closed:referendum,approved:status,ayes,nay,hash,infos}
Expand Down Expand Up @@ -118,24 +109,32 @@ dispatch1({type:`SET_PROPOSALS`,payload:props});
const style1= { width: 410, height:400, background:`white`};
const style2= { width: 410, height:400, background:`red`};
const style3= { width: 410, height:400, background:`green`};
return((selectedAccount && council_members.includes(selectedAccount))?

<div id="scrollableDiv"
if(!selectedAccount||!council_members.includes(selectedAccount)){
return(
<div>
You Are not a Council Member
</div>
)
}

return(
<div className="flex flex-row justify-between p-6">

<div id="scrollableDiv"
style={{
height: 600,
overflow: 'auto',
padding: '0 16px',
border: '1px solid rgba(140, 140, 140, 0.35)',
// border: '1px solid rgba(140, 140, 140, 0.35)',
}}>

<List
dataSource={datas}

dataSource={datas}
renderItem={item => (
<Card
onClick={getproposal}
hoverable
cover={<img alt="example" style={{height:"50%", width:"50%"}} src={item.infos.split(`:`)[1]}/>}
cover={<img alt="example" style={{height:"30%", width:"30%"}} src={item.infos.split(`:`)[1]}/>}
style={(item.status==="AWAITING" && item.referendum==="false")?style1:
((item.status==="AWAITING" && item.referendum==="true")?style2:style3)}>
<List.Item key={item.address}>
Expand All @@ -147,12 +146,21 @@ const style3= { width: 410, height:400, background:`green`};
</Card>
)}

/>
/>



</div>:<div>
You Are not a Council Member
</div>);

</div>
<div >

<Button type="primary" className="bg-blue-600 text-white font-bold py-2 pb-10 text-xl">AYES</Button>
<Button type="primary" className="bg-red-600 text-white font-bold py-2 pb-10 text-xl">NAY</Button>
<p>{selectedProposal?.infos}</p>

</div>


</div>

);

}
42 changes: 26 additions & 16 deletions fs-dapp_2.0/src/components/pages/Roles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,42 @@ export default function Roles() {
api.query.rolesModule.requestedRoles(address0, (data: any) => {
let data0 = data.toHuman();
if(data0) {
console.log(`requested roles:${data}`);
//console.log(`requested roles:${data}`);
let r_session = data0.role.toString();

dispatch1({ type: 'SET_ROLE_IN_SESSION', payload: r_session });
}else{
dispatch1({ type: 'SET_ROLE_IN_SESSION', payload: `` });
}

api.query.backgroundCouncil.proposals((hash: string[]) => {

if (hash.length > 0) {
hash.forEach((x)=>{
if(x.toString()===data0.proposalHash.toString()){

api.query.backgroundCouncil.voting(x.toString(), (data: any) => {
let data1 = data.toHuman();
if (data1 !== null) {
let yes = data1.ayes.length;
let no = data1.nays.length;
dispatch1({ type: 'SET_AYES', payload: yes });
dispatch1({ type: 'SET_NAY', payload: no });
}
});
}
})

}
});

});
//console.log(`role in session:${role_in_session}`)
}, [role_in_session,selectedAccount, blocks, dispatch1, api]);




useEffect(() => {
if (!api || !selectedAccount) return;
let address0 = selectedAccount.address;
Expand Down Expand Up @@ -63,21 +87,7 @@ export default function Roles() {
}
})();
}*/
api.query.backgroundCouncil.proposals((hash: string[]) => {
if (hash.length > 0) {
let hash0 = hash[0];

api.query.backgroundCouncil.voting(hash0, (data: any) => {
let data1 = data.toHuman();
if (data1 !== null) {
let yes = data1.ayes.length;
let no = data1.nays.length;
dispatch1({ type: 'SET_AYES', payload: yes });
dispatch1({ type: 'SET_NAY', payload: no });
}
});
}
});

}, [blocks,selectedAccount, api, dispatch0, dispatch1, dispatch]);

return (
Expand Down
8 changes: 6 additions & 2 deletions fs-dapp_2.0/src/components/shared/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const RolesApp: React.FC = () => {
} else {
let who = selectedAccount.address;
console.log(`User infos: ${infos}`)
let enc= new TextEncoder()
const tx = await api.tx.rolesModule.setRole(who, ROLES[num].toString(),infos);
const fees = await tx.paymentInfo(who);
const injector = await web3FromAddress(who);
Expand Down Expand Up @@ -74,9 +73,14 @@ const RolesApp: React.FC = () => {
console.log(all[1]);
setAcbutton(false)
console.log(infos)
}
}else{setAcbutton(true)}
}, [event,infos,dispatch0]);

useEffect(()=>{

dispatch0({type:`SET_INFOS`,payload:"No Information Provided"});
},[selectedAccount])

return (
<p className="flex-col space-y-2">
<Button
Expand Down
24 changes: 6 additions & 18 deletions fs-dapp_2.0/src/components/shared/referendum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,22 @@ import React from 'react';
import { useConcilSessionContext } from '../../contexts/CouncilSessionContext';
import { useAppContext } from '../../contexts/AppContext';
import { Progress, Space } from 'antd';
import { useEffect } from 'react';

function Referendum() {
const { selectedProposal, council_members,proposals,dispatch1 } = useConcilSessionContext();
const { selectedAccount } = useAppContext();
const { selectedProposal, council_members,proposals,ayes,nay,dispatch1 } = useConcilSessionContext();
const { api,selectedAccount,blocks,accounts } = useAppContext();

const yes = Number(((ayes / council_members.length) * 100).toFixed(1));

proposals.forEach((prop)=>{

if(selectedAccount===prop.Referendum_account){
dispatch1({type:'SET_SELECTED_PROPOSAL',payload:prop});


}
});
if (!selectedProposal) return(
<div>
<p>No votes yet</p>
</div>
);
const yes = Number(((selectedProposal.ayes / council_members.length) * 100).toFixed(1));
console.log(`Number of yes:${selectedProposal.ayes}`)


return (
<div>
{
<Space wrap>
<Progress type="circle" percent={yes} size={80}></Progress>
{selectedProposal.ayes + selectedProposal.nay > 0 ? (
{ayes + nay > 0 ? (
<Progress type="circle" percent={100 - yes} size={80} status="exception"></Progress>
) : (
<p>No votes yet</p>
Expand Down

0 comments on commit 6ca55b6

Please sign in to comment.