Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-torabiv committed Aug 22, 2024
1 parent 1076eba commit 916200a
Show file tree
Hide file tree
Showing 3 changed files with 280 additions and 12 deletions.
56 changes: 45 additions & 11 deletions src/pages/Permissions/Permissions.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,58 @@
import CustomTable, { AccessData, Platform } from '../../components/shared/CustomTable';
import { FaDiscord, FaTelegram, FaGoogle } from 'react-icons/fa';
import { useEffect, useState } from 'react';
import { FaDiscord, FaGoogle } from 'react-icons/fa';
import { useReadContract } from 'wagmi';
import { Address } from 'viem';
import sepoliaChain from '../../utils/contracts/app/sepoliaChain.json';
import CustomTable, {
AccessData,
Platform,
} from '../../components/shared/CustomTable';

const xcolumns: Platform[] = [
{ name: 'Discord', icon: <FaDiscord /> },
{ name: 'Telegram', icon: <FaTelegram /> },
{ name: 'Google', icon: <FaGoogle /> },
];

const ycolumns: AccessData[] = [
{ application: 'TogetherCrew', Discord: true, Telegram: false, Google: true },
{ application: 'MeetWith', Discord: true, Telegram: true, Google: false },
{ application: 'Wallet', Discord: false, Telegram: true, Google: true },
];
export function Permissions() {
const [applications, setApplications] = useState<AccessData[]>([]);

const data: AccessData[] = ycolumns;
const {
data: contractData,
isLoading,
isError,
} = useReadContract({
abi: sepoliaChain.appContractABI,
address: sepoliaChain.appContractAddress as Address,
functionName: 'getApplications',
args: [0, 10],
});

useEffect(() => {
if (contractData) {
console.log({ contractData });

// Map the contract data to match your AccessData structure
const mappedApplications: AccessData[] = contractData.map(
(app: { name: string; account: string }) => ({
application: app.name,
Discord: false,
Google: false,
})
);
setApplications(mappedApplications);
}
}, [contractData]);

if (isLoading) return <div>Loading...</div>;
if (isError) return <div>Error loading data</div>;

export function Permissions() {
return (
<div>
<CustomTable xcolumns={xcolumns} ycolumns={ycolumns} data={data} />
<CustomTable
xcolumns={xcolumns}
ycolumns={applications}
data={applications}
/>
</div>
);
}
235 changes: 235 additions & 0 deletions src/utils/contracts/app/sepoliaChain.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
{
"chainId": 11155111,
"appContractAddress": "0xAA7f2BA598d4ac22ffdbf5DaE9be35C2e4264aE3",
"appContractABI": [
{
"inputs": [
{
"internalType": "address",
"name": "initialAuthority",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{ "internalType": "address", "name": "authority", "type": "address" }
],
"name": "AccessManagedInvalidAuthority",
"type": "error"
},
{
"inputs": [
{ "internalType": "address", "name": "caller", "type": "address" },
{ "internalType": "uint32", "name": "delay", "type": "uint32" }
],
"name": "AccessManagedRequiredDelay",
"type": "error"
},
{
"inputs": [
{ "internalType": "address", "name": "caller", "type": "address" }
],
"name": "AccessManagedUnauthorized",
"type": "error"
},
{ "inputs": [], "name": "ReentrancyGuardReentrantCall", "type": "error" },
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"components": [
{ "internalType": "string", "name": "name", "type": "string" },
{ "internalType": "address", "name": "account", "type": "address" }
],
"indexed": false,
"internalType": "struct IApplicationManager.Application",
"name": "application",
"type": "tuple"
}
],
"name": "ApplicationCreated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"components": [
{ "internalType": "string", "name": "name", "type": "string" },
{ "internalType": "address", "name": "account", "type": "address" }
],
"indexed": false,
"internalType": "struct IApplicationManager.Application",
"name": "application",
"type": "tuple"
}
],
"name": "ApplicationDeleted",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "id",
"type": "uint256"
},
{
"components": [
{ "internalType": "string", "name": "name", "type": "string" },
{ "internalType": "address", "name": "account", "type": "address" }
],
"indexed": false,
"internalType": "struct IApplicationManager.Application",
"name": "application",
"type": "tuple"
}
],
"name": "ApplicationUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "authority",
"type": "address"
}
],
"name": "AuthorityUpdated",
"type": "event"
},
{
"inputs": [],
"name": "authority",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"components": [
{ "internalType": "string", "name": "name", "type": "string" },
{ "internalType": "address", "name": "account", "type": "address" }
],
"internalType": "struct IApplicationManager.Application",
"name": "newApplication",
"type": "tuple"
}
],
"name": "createApplication",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256", "name": "id", "type": "uint256" }
],
"name": "deleteApplication",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256", "name": "id", "type": "uint256" }
],
"name": "getApplication",
"outputs": [
{
"components": [
{ "internalType": "string", "name": "name", "type": "string" },
{ "internalType": "address", "name": "account", "type": "address" }
],
"internalType": "struct IApplicationManager.Application",
"name": "",
"type": "tuple"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256", "name": "start", "type": "uint256" },
{ "internalType": "uint256", "name": "limit", "type": "uint256" }
],
"name": "getApplications",
"outputs": [
{
"components": [
{ "internalType": "string", "name": "name", "type": "string" },
{ "internalType": "address", "name": "account", "type": "address" }
],
"internalType": "struct IApplicationManager.Application[]",
"name": "",
"type": "tuple[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getNextApplicationId",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "isConsumingScheduledOp",
"outputs": [{ "internalType": "bytes4", "name": "", "type": "bytes4" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "newAuthority", "type": "address" }
],
"name": "setAuthority",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256", "name": "id", "type": "uint256" },
{
"components": [
{ "internalType": "string", "name": "name", "type": "string" },
{ "internalType": "address", "name": "account", "type": "address" }
],
"internalType": "struct IApplicationManager.Application",
"name": "updatedApplication",
"type": "tuple"
}
],
"name": "updateApplication",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
}
1 change: 0 additions & 1 deletion src/utils/contracts/eas/sepoliaChain.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"chainId": 11155111,
"easSchemaUUID": "0x85e90e3e16d319578888790af3284fea8bca549305071531e7478e3e0b5e7d6d",
"easContractAddress": "0xC2679fBD37d54388Ce493F1DB75320D236e1815e",
"easContractAbi": [
{
Expand Down

0 comments on commit 916200a

Please sign in to comment.