generated from calimero-network/core-app-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from calimero-network/feat--update-ui
feat: update create proposal logic
- Loading branch information
Showing
11 changed files
with
941 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
import React from 'react'; | ||
import { styled } from 'styled-components'; | ||
|
||
interface FunctionCallProps { | ||
receiver_id: string; | ||
method_name: string; | ||
args: string; | ||
deposit: number; | ||
gas: number; | ||
} | ||
|
||
interface ContextValueProps { | ||
key: number[]; | ||
value: number[]; | ||
} | ||
|
||
interface ApprovalsParams { | ||
num_approvals: number; | ||
} | ||
|
||
interface LimitParams { | ||
active_proposals_limit: number; | ||
} | ||
|
||
interface TransferParams { | ||
receiver_id: string; | ||
amount: number; | ||
} | ||
|
||
interface Action { | ||
scope: string; | ||
params: | ||
| LimitParams | ||
| TransferParams | ||
| ApprovalsParams | ||
| ContextValueProps | ||
| FunctionCallProps; | ||
} | ||
|
||
interface ActionsProps { | ||
actions: Action[]; | ||
} | ||
|
||
interface TableHeaderProps { | ||
columns: number; | ||
bgColor?: boolean; | ||
} | ||
|
||
const GridList = styled.div<TableHeaderProps>` | ||
display: grid; | ||
grid-template-columns: repeat(${(props) => props.columns}, 1fr); | ||
gap: 0.5rem; | ||
background: ${(props) => (props.bgColor ? '#ffa500' : 'transparent')}; | ||
`; | ||
|
||
export default function Actions({ actions }: ActionsProps) { | ||
const getColumnCount = (scope: string) => { | ||
switch (scope) { | ||
case 'Transfer': | ||
case 'SetContextValue': | ||
return 3; | ||
case 'SetActiveProposalsLimit': | ||
case 'SetNumApprovals': | ||
return 2; | ||
case 'ExternalFunctionCall': | ||
return 5; | ||
default: | ||
return 1; | ||
} | ||
}; | ||
|
||
const renderActionContent = (action: Action) => { | ||
switch (action.scope) { | ||
case 'Transfer': | ||
return ( | ||
<> | ||
<div>Scope</div> | ||
<div>Amount</div> | ||
<div>Receiver ID</div> | ||
</> | ||
); | ||
case 'SetContextValue': | ||
return ( | ||
<> | ||
<div>Scope</div> | ||
<div>Key</div> | ||
<div>Vaue ID</div> | ||
</> | ||
); | ||
case 'SetActiveProposalsLimit': | ||
return ( | ||
<> | ||
<div>Scope</div> | ||
<div>Active Proposals Limit</div> | ||
</> | ||
); | ||
case 'SetNumApprovals': | ||
return ( | ||
<> | ||
<div>Scope</div> | ||
<div>Number of Approvals</div> | ||
</> | ||
); | ||
case 'ExternalFunctionCall': | ||
return ( | ||
<> | ||
<div>Scope</div> | ||
<div>Receiver ID</div> | ||
<div>Method</div> | ||
<div>Deposit</div> | ||
<div>Gas</div> | ||
</> | ||
); | ||
default: | ||
return <div>Scope</div>; | ||
} | ||
}; | ||
|
||
const renderActionValues = (action: Action) => { | ||
switch (action.scope) { | ||
case 'Transfer': | ||
const transferParams = action.params as TransferParams; | ||
return ( | ||
<> | ||
<div>{action.scope}</div> | ||
<div>{transferParams.amount}</div> | ||
<div>{transferParams.receiver_id}</div> | ||
</> | ||
); | ||
case 'SetContextValue': | ||
const contextValueParams = action.params as ContextValueProps; | ||
return ( | ||
<> | ||
<div>{action.scope}</div> | ||
<div>{String.fromCharCode(...contextValueParams.key)}</div> | ||
<div>{String.fromCharCode(...contextValueParams.value)}</div> | ||
</> | ||
); | ||
case 'SetActiveProposalsLimit': | ||
const limitParams = action.params as LimitParams; | ||
return ( | ||
<> | ||
<div>{action.scope}</div> | ||
<div>{limitParams.active_proposals_limit}</div> | ||
</> | ||
); | ||
case 'SetNumApprovals': | ||
const approvalParams = action.params as ApprovalsParams; | ||
return ( | ||
<> | ||
<div>{action.scope}</div> | ||
<div>{approvalParams.num_approvals}</div> | ||
</> | ||
); | ||
case 'ExternalFunctionCall': | ||
const functionParams = action.params as FunctionCallProps; | ||
return ( | ||
<> | ||
<div>{action.scope}</div> | ||
<div>{functionParams.receiver_id}</div> | ||
<div>{functionParams.method_name}</div> | ||
<div>{functionParams.deposit}</div> | ||
<div>{functionParams.gas}</div> | ||
</> | ||
); | ||
default: | ||
return <div>{action.scope}</div>; | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<GridList columns={getColumnCount(actions[0].scope)} bgColor> | ||
{renderActionContent(actions[0])} | ||
</GridList> | ||
<div> | ||
{actions.map((action, index) => ( | ||
<GridList key={index} columns={getColumnCount(action.scope)}> | ||
{renderActionValues(action)} | ||
</GridList> | ||
))} | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react'; | ||
import { FormGroup } from './CreateProposalPopup'; | ||
|
||
interface ActionsDropdownProps { | ||
actionType: string; | ||
handleInputChange: (e: React.ChangeEvent<HTMLSelectElement>) => void; | ||
} | ||
|
||
export enum ActionTypes { | ||
CROSS_CONTRACT_CALL = 'Cross contract call', | ||
TRANSFER = 'Transfer', | ||
SET_CONTEXT_VARIABLE = 'Set context variable', | ||
CHANGE_APPROVALS_NEEDED = 'Change number of approvals needed', | ||
CHANGE_MAX_ACTIVE_PROPOSALS = 'Change number of maximum active proposals', | ||
} | ||
|
||
export const actionTypes = [ | ||
{ | ||
id: 'CROSS_CONTRACT_CALL', | ||
label: 'Cross contract call', | ||
}, | ||
{ | ||
id: 'TRANSFER', | ||
label: 'Transfer', | ||
}, | ||
{ | ||
id: 'SET_CONTEXT_VARIABLE', | ||
label: 'Set context variable', | ||
}, | ||
{ | ||
id: 'CHANGE_APPROVALS_NEEDED', | ||
label: 'Change number of approvals needed', | ||
}, | ||
{ | ||
id: 'CHANGE_MAX_ACTIVE_PROPOSALS', | ||
label: 'Change number of maximum active proposals', | ||
}, | ||
]; | ||
|
||
export default function ActionsDropdown({ | ||
actionType, | ||
handleInputChange, | ||
}: ActionsDropdownProps) { | ||
return ( | ||
<FormGroup> | ||
<label htmlFor="actionType">Action Type</label> | ||
<select | ||
id="actionType" | ||
name="actionType" | ||
value={actionType} | ||
onChange={handleInputChange} | ||
required | ||
> | ||
{actionTypes.map((action, i) => ( | ||
<option key={i} value={action.label}> | ||
{action.label} | ||
</option> | ||
))} | ||
</select> | ||
</FormGroup> | ||
); | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/components/proposals/ChangeApprovalsNeededForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { FormGroup, ProposalData } from './CreateProposalPopup'; | ||
|
||
interface ChangeApprovalsNeededFormProps { | ||
proposalForm: ProposalData; | ||
handleInputChange: ( | ||
e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>, | ||
) => void; | ||
} | ||
|
||
export default function ChangeApprovalsNeededForm({ | ||
proposalForm, | ||
handleInputChange, | ||
}: ChangeApprovalsNeededFormProps) { | ||
return ( | ||
<FormGroup> | ||
<label htmlFor="minApprovals">Minimum Approvals Required</label> | ||
<input | ||
type="number" | ||
id="minApprovals" | ||
name="minApprovals" | ||
placeholder="2" | ||
value={proposalForm.minApprovals} | ||
onChange={handleInputChange} | ||
min="1" | ||
required | ||
/> | ||
</FormGroup> | ||
); | ||
} |
Oops, something went wrong.