Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from meemproject/dev
Browse files Browse the repository at this point in the history
Dev -> Stage
  • Loading branch information
kengoldfarb authored Aug 11, 2022
2 parents 061db06 + 3ed9ebc commit d0f713c
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 10 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## [1.0.1](https://github.com/meemproject/epm/compare/v1.0.0...v1.0.1) (2022-07-29)


### Bug Fixes

* add bundle facet not fetching contract ([880bde6](https://github.com/meemproject/epm/commit/880bde6))

# 1.0.0 (2022-07-26)

## [1.1.3](https://github.com/meemproject/clubs-web/compare/v1.1.2...v1.1.3) (2022-06-09)

## [1.1.2](https://github.com/meemproject/clubs-web/compare/v1.1.1...v1.1.2) (2022-06-09)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meemproject/epm",
"version": "0.0.1",
"version": "1.0.1",
"private": true,
"author": "Meem Project",
"contributors": [
Expand Down Expand Up @@ -94,4 +94,4 @@
"typechain": "^6.0.2",
"typescript": "4.6.3"
}
}
}
3 changes: 3 additions & 0 deletions src/components/Atoms/FacetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ export const FacetList: React.FC<IProps> = ({
<>
<Switch
key={`${contract?.id}-${selector}`}
disabled={
!isEnabled
}
checked={
isInUse
}
Expand Down
43 changes: 40 additions & 3 deletions src/components/Contracts/DeployContract.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import log from '@kengoldfarb/log'
import { Text, Button, TextInput, Space, Title, Modal } from '@mantine/core'
import {
Text,
Button,
TextInput,
Space,
Title,
Modal,
Textarea
} from '@mantine/core'
import { useForm } from '@mantine/form'
import { showNotification } from '@mantine/notifications'
import { chains, MeemAPI } from '@meemproject/api'
Expand Down Expand Up @@ -60,8 +68,23 @@ export const DeployContract: React.FC<IProps> = ({
const handleDeploy = async () => {
const args: any[] = []
for (let i = 0; i < inputs.length; i += 1) {
// @ts-ignore
args.push(form.values[`args${i}`])
const input = inputs[i]
switch (input.type) {
case 'address[]': {
// @ts-ignore
const vals = form.values[`args${i}`].split('\n')

args.push(vals.map(item => item.trim()))
break
}

case 'address':
default: {
// @ts-ignore
args.push(form.values[`args${i}`])
break
}
}
}

try {
Expand Down Expand Up @@ -144,6 +167,20 @@ export const DeployContract: React.FC<IProps> = ({
>
{inputs.map((input, i) => {
switch (input.type) {
case 'address[]':
return (
<Textarea
key={`input-${name}`}
label={input.name}
placeholder={
input.type === 'address[]'
? '0x...\n0x...'
: ''
}
// @ts-ignore
{...form.getInputProps(`args${i}`)}
/>
)
case 'address':
default: {
return (
Expand Down
58 changes: 54 additions & 4 deletions src/components/ManageDiamond/ManageDiamondContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const ManageDiamondContainer: React.FC = () => {
const [fetchedAddress, setFetchedAddress] = useState<string>()
const [fetchedChainId, setFetchedChainId] = useState<number>()
const [contractOwner, setContractOwner] = useState<string>()
const [isUpgrader, setIsUpgrader] = useState<boolean>(false)
const [hasFoundAllFacets, setHasFoundAllFacets] = useState(true)
const [facets, setFacets] = useState<
{ selectors: string[]; target: string }[]
Expand Down Expand Up @@ -331,11 +332,15 @@ export const ManageDiamondContainer: React.FC = () => {
signer
)

const [facetResult, bytecodeResult, ownerResult] =
const [facetResult, bytecodeResult, ownerResult, hasRoleResult] =
await Promise.allSettled([
diamond.facets(),
web3Provider?.getCode(form.values.address),
diamond.owner()
diamond.owner(),
diamond.hasRole(
'0x189ab7a9244df0848122154315af71fe140f3db0fe014031783b0946b8c9d2e3',
signer?.getAddress()
)
])

const result =
Expand All @@ -347,6 +352,9 @@ export const ManageDiamondContainer: React.FC = () => {
const owner =
ownerResult.status === 'fulfilled' && ownerResult.value

const hasRole =
hasRoleResult.status === 'fulfilled' && hasRoleResult.value

form.values.facets.splice(0, form.values.facets.length)
// form.setFieldValue('facets', formList(result))
if (Array.isArray(result)) {
Expand All @@ -362,6 +370,7 @@ export const ManageDiamondContainer: React.FC = () => {
setFacets(result)
setBytecode(bc && bc !== '0x' ? bc : undefined)
setContractOwner(owner)
setIsUpgrader(hasRole)
setFetchedAddress(form.values.address)
setFetchedChainId(chainId)
setIsDiamond(!!result)
Expand Down Expand Up @@ -550,6 +559,8 @@ export const ManageDiamondContainer: React.FC = () => {
}
}, [data, isLoading, facets])

const shouldShowUpgradeControls = isContractOwner || isUpgrader

return (
<Page>
<form onSubmit={form.onSubmit(() => handleSave())}>
Expand Down Expand Up @@ -750,6 +761,12 @@ export const ManageDiamondContainer: React.FC = () => {
You are the owner of this contract.
</Text>
)}
{isContractOwner && !isUpgrader && (
<Text color="dimmed" size="sm">
You are not listed as an upgrader on
the contract
</Text>
)}
{!isContractOwner && (
<Text color="dimmed" size="sm">
The connected account is not the
Expand All @@ -758,6 +775,39 @@ export const ManageDiamondContainer: React.FC = () => {
)}
</Timeline.Item>
)}
{bytecode && isUpgrader && (
<Timeline.Item
active
bullet={
<ThemeIcon
color={isUpgrader ? 'green' : 'red'}
>
{isUpgrader ? (
<Check size={20} />
) : (
<FaceIdError size={20} />
)}
</ThemeIcon>
}
title={
isUpgrader
? 'Contract Upgrader'
: 'Not Contract Upgrader'
}
>
{isUpgrader && (
<Text color="dimmed" size="sm">
You have the upgrader role on this
contract
</Text>
)}
{!isUpgrader && !isContractOwner && (
<Text color="dimmed" size="sm">
{`You can't upgrade this contract`}
</Text>
)}
</Timeline.Item>
)}
{bytecode && (
<Timeline.Item
active
Expand Down Expand Up @@ -792,7 +842,7 @@ export const ManageDiamondContainer: React.FC = () => {
{isDiamond && (
<>
<Space h={48} />
{isContractOwner && (
{shouldShowUpgradeControls && (
<div className={classes.section_wrapper}>
<Text size="xl">Facets</Text>
<Space w={12} />
Expand Down Expand Up @@ -826,7 +876,7 @@ export const ManageDiamondContainer: React.FC = () => {
proxyContract as ContractInstances
}
isLoading={isLoading}
isEnabled={isContractOwner}
isEnabled={shouldShowUpgradeControls}
/>
)}
{!hasFoundAllFacets && (
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/contracts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export const SUB_GET_MY_CONTRACTS = gql`
subscription SubGetMyContracts($address: String!) {
Wallets(where: { address: { _ilike: $address } }) {
id
WalletContractInstances {
WalletContractInstances(order_by: { createdAt: desc }) {
id
note
name
Expand Down
24 changes: 24 additions & 0 deletions src/lib/diamond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,29 @@ export const diamondABI = [
{
stateMutability: 'payable',
type: 'receive'
},
{
inputs: [
{
internalType: 'bytes32',
name: 'role',
type: 'bytes32'
},
{
internalType: 'address',
name: 'user',
type: 'address'
}
],
name: 'hasRole',
outputs: [
{
internalType: 'bool',
name: '',
type: 'bool'
}
],
stateMutability: 'view',
type: 'function'
}
]

0 comments on commit d0f713c

Please sign in to comment.