-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d0cbcc
commit 4d6d1a3
Showing
11 changed files
with
269 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
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
42 changes: 39 additions & 3 deletions
42
packages/apps/rwa-demo/src/components/AgentsList/AgentsList.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
77 changes: 77 additions & 0 deletions
77
packages/apps/rwa-demo/src/components/SetComplianceForm/SetComplianceForm.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,77 @@ | ||
import { useAccount } from '@/hooks/account'; | ||
import { useNetwork } from '@/hooks/networks'; | ||
import type { ISetComplianceProps } from '@/services/setCompliance'; | ||
import { setCompliance } from '@/services/setCompliance'; | ||
import { getClient } from '@/utils/client'; | ||
import { Button, NumberField } from '@kadena/kode-ui'; | ||
import { | ||
RightAside, | ||
RightAsideContent, | ||
RightAsideFooter, | ||
RightAsideHeader, | ||
} from '@kadena/kode-ui/patterns'; | ||
import type { FC } from 'react'; | ||
import { useState } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
|
||
interface IProps { | ||
onClose: () => void; | ||
} | ||
|
||
export const SetComplianceForm: FC<IProps> = ({ onClose }) => { | ||
const { activeNetwork } = useNetwork(); | ||
const { account, sign } = useAccount(); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const [_, setError] = useState<string | null>(null); | ||
const { register, handleSubmit } = useForm<ISetComplianceProps>({ | ||
defaultValues: { | ||
maxBalance: 0, | ||
maxSupply: 0, | ||
}, | ||
}); | ||
|
||
const onSubmit = async (data: ISetComplianceProps) => { | ||
setError(null); | ||
try { | ||
const tx = await setCompliance(data, activeNetwork, account!); | ||
|
||
const signedTransaction = await sign(tx); | ||
if (!signedTransaction) return; | ||
|
||
const client = getClient(); | ||
const res = await client.submit(signedTransaction); | ||
|
||
await client.listen(res); | ||
console.log('DONE'); | ||
} catch (e: any) { | ||
setError(e?.message || e); | ||
} | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<RightAside isOpen onClose={onClose}> | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
<RightAsideHeader label="Set compliance" /> | ||
<RightAsideContent> | ||
<NumberField | ||
label="Max Balance" | ||
{...register('maxBalance', { required: true })} | ||
/> | ||
<NumberField | ||
label="Max Supply" | ||
{...register('maxSupply', { required: true })} | ||
/> | ||
</RightAsideContent> | ||
<RightAsideFooter> | ||
<Button onPress={onClose} variant="transparent"> | ||
Cancel | ||
</Button> | ||
<Button type="submit">Set Compliance</Button> | ||
</RightAsideFooter> | ||
</form> | ||
</RightAside> | ||
</> | ||
); | ||
}; |
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,28 @@ | ||
import type { INetwork } from '@/components/NetworkProvider/NetworkProvider'; | ||
import { ADMIN } from '@/constants'; | ||
import { Pact } from '@kadena/client'; | ||
import type { ConnectedAccount } from '@kadena/spirekey-sdk'; | ||
|
||
export interface IRemoveAgentProps { | ||
agent: string; | ||
} | ||
|
||
export const removeAgent = async ( | ||
data: IRemoveAgentProps, | ||
network: INetwork, | ||
account: ConnectedAccount, | ||
) => { | ||
return Pact.builder | ||
.execution(`(RWA.agent-role.remove-agent (read-string 'agent))`) | ||
.setMeta({ | ||
senderAccount: ADMIN.account, | ||
chainId: network.chainId, | ||
}) | ||
.addSigner(ADMIN.publicKey, (withCap) => [ | ||
withCap(`RWA.agent-role.ONLY-OWNER`), | ||
withCap(`coin.GAS`), | ||
]) | ||
.addData('agent', data.agent) | ||
.setNetworkId(network.networkId) | ||
.createTransaction(); | ||
}; |
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,29 @@ | ||
import type { INetwork } from '@/components/NetworkProvider/NetworkProvider'; | ||
import { ADMIN } from '@/constants'; | ||
import { Pact } from '@kadena/client'; | ||
import type { ConnectedAccount } from '@kadena/spirekey-sdk'; | ||
|
||
export interface ISetComplianceProps { | ||
maxBalance: number; | ||
maxSupply: number; | ||
} | ||
|
||
export const setCompliance = async ( | ||
data: ISetComplianceProps, | ||
network: INetwork, | ||
account: ConnectedAccount, | ||
) => { | ||
return Pact.builder | ||
.execution( | ||
` (RWA.max-balance-compliance.set-max-balance 60.0) | ||
(RWA.max-balance-compliance.set-max-supply 100.0)`, | ||
) | ||
.setMeta({ | ||
senderAccount: ADMIN.account, | ||
chainId: network.chainId, | ||
}) | ||
.addSigner(ADMIN.publicKey) | ||
|
||
.setNetworkId(network.networkId) | ||
.createTransaction(); | ||
}; |
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
17 changes: 17 additions & 0 deletions
17
packages/libs/kode-ui/src/patterns/CompactTable/TableFormatters/FormatActions.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,17 @@ | ||
import type { ReactElement } from 'react'; | ||
import React from 'react'; | ||
import type { ICompactTableFormatterProps } from './types'; | ||
|
||
export interface IActionProps { | ||
trigger: ReactElement; | ||
} | ||
|
||
export const FormatActions = ({ trigger }: IActionProps) => { | ||
const Component = ({ value }: ICompactTableFormatterProps) => { | ||
return React.cloneElement(trigger, { | ||
...trigger.props, | ||
onPress: () => trigger.props.onPress(value), | ||
}); | ||
}; | ||
return Component; | ||
}; |
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