Skip to content

Commit

Permalink
Investor Menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkazu committed Apr 18, 2024
1 parent 384aa59 commit 2e949a1
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 13 deletions.
4 changes: 2 additions & 2 deletions fs-dapp_2.0/src/components/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useAppContext } from '../../contexts/AppContext';
import { useAccountContext } from '../../contexts/Account_Context';
import { Chart as ChartJS, ArcElement, Tooltip, Legend } from 'chart.js';
import { Pie } from 'react-chartjs-2';
import BN from 'bn.js';
import {BN,formatBalance} from '@polkadot/util';
import { toUnit } from '../shared/utils';
import { NavLink } from 'react-router-dom';
import { all } from 'axios';
Expand Down Expand Up @@ -133,7 +133,7 @@ export default function Dashboard() {
<div>
<h1 className="text-3xl text-slate-700 font-bold">DASHBOARD</h1>
<p className="text-xl font-bold">
House Fund: {!treasury_balance ? '0' : toUnit(treasury_balance, 3).toString()} FS
House Fund: {!treasury_balance ? '0' :formatBalance(treasury_balance,{ decimals:12, withUnit:'FS',withSi: true, withZero: false })}
</p>
<p className="text-xl font-bold">Total Number of Users: {total_users_nbr}</p>
</div>
Expand Down
67 changes: 60 additions & 7 deletions fs-dapp_2.0/src/components/pages/Investor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,87 @@ import React, { useEffect,useState } from 'react';
import { useAppContext } from '../../contexts/AppContext';
import { arrangeText } from './Council';
import { InvestorData } from '@/src/contexts/types';
import {BN,formatBalance} from '@polkadot/util';
import { Card, Button } from 'antd';

const data0:InvestorData={name:"",address:"",balance:"",fund_share:"",available_funds:"", reserved_funds:"", invested_funds:""}
const inv_image = "../../../INVESTOR.png"


export default function Investors(){
const { api, blocks, selectedAccount, web3Name, credentials, dispatch } = useAppContext();
const { role, balance,investor, dispatch0 } = useAccountContext();
//Get user infos
const[idata,setIdatas] = useState<InvestorData|undefined>();
const[idata,setIdatas] = useState<InvestorData>();



useEffect(()=>{
if (!api||!selectedAccount) return;
let address0=selectedAccount.address;
api.query.rolesModule.investorLog(address0,(data:any)=>{
let data0= data.toHuman();
api.query.system.account(address0, ({ data: free }: { data: { free: BN } }) => {
formatBalance.setDefaults({ decimals: 12, unit: 'FS' });
const free0 = formatBalance(free.free,{ withSi: true, withZero: false });
dispatch0({ type: 'SET_BALANCE', payload: free0 });


});
api.query.rolesModule.investorLog(address0,(datalog:any)=>{
let data0= datalog.toHuman();
if(data0){
let txt = data0.infos
let infos = arrangeText(txt);
let infos = arrangeText(txt);
let datas0:InvestorData={...data0,name:infos[0],address:selectedAccount.address,balance:balance,fund_share:data0.share};

// let datas:InvestorData={name:infos[0],address:selectedAccount.address,balance:balance,fund_share:data0.share}
api.query.housingFundModule.contributions(address0,(data:any)=>{
let data0 = data.toHuman();
if (data0){
formatBalance.setDefaults({ decimals: 12, unit: 'FS' });

let available_funds=formatBalance(new BN(data0.availableBalance.toString().split(',').join('')),{ withSi: true, withZero: false });
let reserved_funds=formatBalance(new BN(data0.reservedBalance.toString().split(',').join('')),{ withSi: true, withZero: false });
let invested_funds=formatBalance(new BN(data0.contributedBalance.toString().split(',').join('')),{ withSi: true, withZero: false });

let datas:InvestorData={...datas0,available_funds,reserved_funds,invested_funds};
setIdatas(datas)
dispatch0({ type: 'SET_INVESTOR', payload: datas });
}
})
}
})
})

},[selectedAccount,blocks,api,dispatch0,balance])


const style1= { width: 450, height:400, background:`white`};

return(
<div>
Investor Page
<div className=' flex flex-row'>
<p>
{
investor?
<Card
className=' text-xl'
cover={<img alt="example" style={{height:"30%", width:"30%"}} src={inv_image}/>}
style={style1}
>
<p><b>Investor Name: </b>{investor.name.split(':')[1]}</p>
<p><b>Wallet Balance:</b> {investor.balance}</p>
<p><b>Available Balance in Fund: </b>{investor.available_funds}</p>
<p><b>Share in Housing Fund:</b> {investor.fund_share}</p>
<p><b>Reserved for Purchase:</b> {investor.reserved_funds}</p>
<p><b>Amount Invested: </b>{investor.invested_funds}</p>
</Card>:"NO DATA"}
</p>

<p>
<Button>Contribute to fund</Button>
</p>

</div>


</div>
)
}
2 changes: 1 addition & 1 deletion fs-dapp_2.0/src/contexts/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createContext, useContext, useReducer, ReactNode } from 'react';
import { ApiPromise } from '@polkadot/api';
import { InjectedAccountWithMeta } from '@polkadot/extension-inject/types';
import { AppState } from './types';
import BN from 'bn.js';
import {BN} from '@polkadot/util';

const initialState: AppState = {
api: null,
Expand Down
6 changes: 4 additions & 2 deletions fs-dapp_2.0/src/contexts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ export interface DataType {
}

export interface InvestorData{
name:string|undefined;
name:string;
address:string;
balance: string|undefined;
balance: string;
fund_share: string;
available_funds:string;
reserved_funds:string;
invested_funds:string;

}

Expand Down
13 changes: 13 additions & 0 deletions pallets/housing_fund/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,19 @@ pub mod pallet {
ExistenceRequirement::AllowDeath,
)?;

//Contributors shares are updated in their respective profiles
let shares = Self::get_contribution_share();
//let keys = ROLES::InvestorLog::<T>::ke
for i in shares {
if ROLES::InvestorLog::<T>::contains_key(i.account_id.clone()) {
let mut inv=ROLES::InvestorLog::<T>::get(&i.account_id).unwrap();
inv.share=i.share;
ROLES::InvestorLog::<T>::mutate(i.account_id.clone(),|val|{
*val=Some(inv);
});
}
}

// Emit an event.
Self::deposit_event(Event::ContributeSucceeded(who, amount, block_number));

Expand Down
3 changes: 2 additions & 1 deletion pallets/roles/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub use frame_support::{
dispatch::GetDispatchInfo,
PalletId,
};
use sp_runtime::Percent;
pub use sp_std::vec::Vec;
pub use frame_system::{ensure_signed, ensure_root, pallet_prelude::*, RawOrigin};
pub use scale_info::{prelude::vec, TypeInfo};
Expand Down Expand Up @@ -94,7 +95,7 @@ impl<T: Config> Proposal<T>{
pub struct Investor<T: Config> {
pub account_id: T::AccountId,
pub age: BlockNumberOf<T>,
pub share: BalanceOf<T>,
pub share: Percent,
pub selections: u32,
pub infos: BoundedVecOf<T>
}
Expand Down

0 comments on commit 2e949a1

Please sign in to comment.