Include Send among available auth types
This commit is contained in:
parent
7526cc91d1
commit
ab801768b9
@ -49,6 +49,7 @@ export function AuthzSendGrantMsg(
|
|||||||
denom: string,
|
denom: string,
|
||||||
spendLimit: number,
|
spendLimit: number,
|
||||||
expiration: number,
|
expiration: number,
|
||||||
|
allowList?: string[],
|
||||||
): Msg {
|
): Msg {
|
||||||
const sendAuthValue = SendAuthorization.encode(
|
const sendAuthValue = SendAuthorization.encode(
|
||||||
SendAuthorization.fromPartial({
|
SendAuthorization.fromPartial({
|
||||||
@ -58,15 +59,18 @@ export function AuthzSendGrantMsg(
|
|||||||
denom,
|
denom,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
//allowList,
|
||||||
}),
|
}),
|
||||||
).finish()
|
).finish()
|
||||||
|
|
||||||
const grantValue = MsgGrant.fromPartial({
|
const grantValue = MsgGrant.fromPartial({
|
||||||
grant: {
|
grant: {
|
||||||
authorization: {
|
authorization: {
|
||||||
typeUrl: '/cosmos.bank.v1beta1.SendAuthorization',
|
typeUrl: '/cosmos.bank.v1beta1.SendAuthorization',
|
||||||
value: sendAuthValue,
|
value: sendAuthValue,
|
||||||
},
|
},
|
||||||
//expiration: { seconds: BigInt(expiration).valueOf() },
|
// TODO: fix expiration issue
|
||||||
|
expiration: expiration ? { seconds: BigInt(expiration) } : undefined,
|
||||||
},
|
},
|
||||||
grantee,
|
grantee,
|
||||||
granter,
|
granter,
|
||||||
|
@ -11,14 +11,14 @@ import { Alert } from 'components/Alert'
|
|||||||
import { Conditional } from 'components/Conditional'
|
import { Conditional } from 'components/Conditional'
|
||||||
import { ContractPageHeader } from 'components/ContractPageHeader'
|
import { ContractPageHeader } from 'components/ContractPageHeader'
|
||||||
import { FormControl } from 'components/FormControl'
|
import { FormControl } from 'components/FormControl'
|
||||||
import { TextInput } from 'components/forms/FormInput'
|
import { NumberInput, TextInput } from 'components/forms/FormInput'
|
||||||
import { useInputState } from 'components/forms/FormInput.hooks'
|
import { useInputState, useNumberInputState } from 'components/forms/FormInput.hooks'
|
||||||
import { InputDateTime } from 'components/InputDateTime'
|
import { InputDateTime } from 'components/InputDateTime'
|
||||||
import { LinkTabs } from 'components/LinkTabs'
|
import { LinkTabs } from 'components/LinkTabs'
|
||||||
import { authzLinkTabs } from 'components/LinkTabs.data'
|
import { authzLinkTabs } from 'components/LinkTabs.data'
|
||||||
import { getConfig } from 'config'
|
import { getConfig } from 'config'
|
||||||
import type { Msg } from 'config/authz'
|
import type { Msg } from 'config/authz'
|
||||||
import { AuthzGenericGrantMsg } from 'config/authz'
|
import { AuthzGenericGrantMsg, AuthzSendGrantMsg } from 'config/authz'
|
||||||
import { useGlobalSettings } from 'contexts/globalSettings'
|
import { useGlobalSettings } from 'contexts/globalSettings'
|
||||||
import type { NextPage } from 'next'
|
import type { NextPage } from 'next'
|
||||||
import { NextSeo } from 'next-seo'
|
import { NextSeo } from 'next-seo'
|
||||||
@ -66,6 +66,22 @@ const Grant: NextPage = () => {
|
|||||||
subtitle: 'The spend limit denom',
|
subtitle: 'The spend limit denom',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const spendLimitState = useNumberInputState({
|
||||||
|
id: 'spend-limit',
|
||||||
|
name: 'spendLimit',
|
||||||
|
title: 'Spend Limit',
|
||||||
|
placeholder: `1000000`,
|
||||||
|
subtitle: 'The spend limit',
|
||||||
|
})
|
||||||
|
|
||||||
|
const allowListState = useInputState({
|
||||||
|
id: 'allow-list',
|
||||||
|
name: 'allowList',
|
||||||
|
title: 'Allow List',
|
||||||
|
placeholder: `stars1..., stars1...`,
|
||||||
|
subtitle: 'Comma separated list of addresses to allow transactions to',
|
||||||
|
})
|
||||||
|
|
||||||
const messageToSign = () => {
|
const messageToSign = () => {
|
||||||
if (authType === 'Generic') {
|
if (authType === 'Generic') {
|
||||||
if (genericAuthType === 'MsgSend') {
|
if (genericAuthType === 'MsgSend') {
|
||||||
@ -92,6 +108,15 @@ const Grant: NextPage = () => {
|
|||||||
(expiration?.getTime() as number) / 1000 || 0,
|
(expiration?.getTime() as number) / 1000 || 0,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
} else if (authType === 'Send') {
|
||||||
|
return AuthzSendGrantMsg(
|
||||||
|
wallet.address || '',
|
||||||
|
granteeAddressState.value,
|
||||||
|
spendLimitDenomState.value,
|
||||||
|
spendLimitState.value,
|
||||||
|
(expiration?.getTime() as number) / 1000 || 0,
|
||||||
|
allowListState.value ? allowListState.value.split(',').map((address) => address.trim()) : [],
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const handleSendMessage = async () => {
|
const handleSendMessage = async () => {
|
||||||
@ -130,9 +155,7 @@ const Grant: NextPage = () => {
|
|||||||
value={authType}
|
value={authType}
|
||||||
>
|
>
|
||||||
<option value="Generic">Generic</option>
|
<option value="Generic">Generic</option>
|
||||||
<option disabled value="Send">
|
<option value="Send">Send</option>
|
||||||
Send
|
|
||||||
</option>
|
|
||||||
<option disabled value="Execute Smart Contract">
|
<option disabled value="Execute Smart Contract">
|
||||||
Execute Smart Contract
|
Execute Smart Contract
|
||||||
</option>
|
</option>
|
||||||
@ -170,10 +193,13 @@ const Grant: NextPage = () => {
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</Conditional>
|
</Conditional>
|
||||||
<TextInput className="w-1/3" {...granteeAddressState} />
|
<TextInput className="w-2/5" {...granteeAddressState} />
|
||||||
<Conditional test={authType === 'Send'}>
|
<Conditional test={authType === 'Send'}>
|
||||||
|
<NumberInput className="w-1/4" {...spendLimitState} />
|
||||||
<TextInput className="w-1/4" {...spendLimitDenomState} />
|
<TextInput className="w-1/4" {...spendLimitDenomState} />
|
||||||
|
{/* <TextInput className="w-2/5" {...allowListState} /> */}
|
||||||
</Conditional>
|
</Conditional>
|
||||||
|
<Conditional test={authType === 'Generic'}>
|
||||||
<FormControl
|
<FormControl
|
||||||
className="w-1/4"
|
className="w-1/4"
|
||||||
htmlId="expiration"
|
htmlId="expiration"
|
||||||
@ -187,7 +213,9 @@ const Grant: NextPage = () => {
|
|||||||
onChange={(date) =>
|
onChange={(date) =>
|
||||||
date
|
date
|
||||||
? setExpiration(
|
? setExpiration(
|
||||||
timezone === 'Local' ? date : new Date(date?.getTime() - new Date().getTimezoneOffset() * 60 * 1000),
|
timezone === 'Local'
|
||||||
|
? date
|
||||||
|
: new Date(date?.getTime() - new Date().getTimezoneOffset() * 60 * 1000),
|
||||||
)
|
)
|
||||||
: setExpiration(undefined)
|
: setExpiration(undefined)
|
||||||
}
|
}
|
||||||
@ -200,6 +228,7 @@ const Grant: NextPage = () => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
</Conditional>
|
||||||
<button
|
<button
|
||||||
className="px-4 py-2 font-bold text-white bg-stargaze rounded-md"
|
className="px-4 py-2 font-bold text-white bg-stargaze rounded-md"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user