diff --git a/.changeset/violet-pillows-exercise.md b/.changeset/violet-pillows-exercise.md new file mode 100644 index 00000000..a2545a1f --- /dev/null +++ b/.changeset/violet-pillows-exercise.md @@ -0,0 +1,5 @@ +--- +'@bnb-chain/greenfield-js-sdk': patch +--- + +fix: PutPolicy if resource is empty use `[]` not `['']` diff --git a/examples/nextjs/src/components/policy/groupPolicy/index.tsx b/examples/nextjs/src/components/policy/groupPolicy/index.tsx index 4dd0a3ed..a6f2bec8 100644 --- a/examples/nextjs/src/components/policy/groupPolicy/index.tsx +++ b/examples/nextjs/src/components/policy/groupPolicy/index.tsx @@ -28,7 +28,7 @@ export const GroupPolicy = () => { const statement: PermissionTypes.Statement = { effect: PermissionTypes.Effect.EFFECT_ALLOW, actions: [PermissionTypes.ActionType.ACTION_UPDATE_GROUP_MEMBER], - resources: [''], + resources: [], }; const tx = await client.group.putGroupPolicy(address, policyGroupInfo.groupName, { diff --git a/examples/nextjs/src/components/policy/objectPolicy/index.tsx b/examples/nextjs/src/components/policy/objectPolicy/index.tsx index ec82a9d1..45607b9d 100644 --- a/examples/nextjs/src/components/policy/objectPolicy/index.tsx +++ b/examples/nextjs/src/components/policy/objectPolicy/index.tsx @@ -38,7 +38,7 @@ export const ObjectPolicy = () => { const statement: PermissionTypes.Statement = { effect: PermissionTypes.Effect.EFFECT_ALLOW, actions: [PermissionTypes.ActionType.ACTION_GET_OBJECT], - resources: [''], + resources: [], }; const tx = await client.object.putObjectPolicy( diff --git a/packages/chain-sdk/src/messages/greenfield/storage/MsgPutPolicy.ts b/packages/chain-sdk/src/messages/greenfield/storage/MsgPutPolicy.ts index e9b1a181..b08e31ff 100644 --- a/packages/chain-sdk/src/messages/greenfield/storage/MsgPutPolicy.ts +++ b/packages/chain-sdk/src/messages/greenfield/storage/MsgPutPolicy.ts @@ -1,4 +1,20 @@ -export const MsgPutPolicySDKTypeEIP712 = { +import type { EIP712Msg } from '@/messages/utils'; +import cloneDeep from 'lodash.clonedeep'; + +export const getMsgPutPolicySDKTypeEIP712 = (resource: string[]) => { + const res: EIP712Msg = cloneDeep(MsgPutPolicySDKTypeEIP712); + + if (resource.length !== 0) { + res.TypeMsg1Statements.push({ + name: 'resources', + type: 'string[]', + }); + } + + return res; +}; + +const MsgPutPolicySDKTypeEIP712 = { Msg1: [ { name: 'type', @@ -36,21 +52,21 @@ export const MsgPutPolicySDKTypeEIP712 = { }, ], TypeMsg1Statements: [ - { - name: 'effect', - type: 'string', - }, { name: 'actions', type: 'string[]', }, { - name: 'resources', - type: 'string[]', + name: 'effect', + type: 'string', }, { name: 'expiration_time', type: 'string', }, + // { + // name: 'resources', + // type: 'string[]', + // }, ], }; diff --git a/packages/chain-sdk/src/messages/greenfield/storage/MsgUpdateGroupMember.ts b/packages/chain-sdk/src/messages/greenfield/storage/MsgUpdateGroupMember.ts index 50bcea61..054a1c8f 100644 --- a/packages/chain-sdk/src/messages/greenfield/storage/MsgUpdateGroupMember.ts +++ b/packages/chain-sdk/src/messages/greenfield/storage/MsgUpdateGroupMember.ts @@ -1,3 +1,4 @@ +import type { EIP712Msg } from '@/messages/utils'; import { MsgGroupMember } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx'; import cloneDeep from 'lodash.clonedeep'; @@ -8,9 +9,7 @@ export const getMsgUpdateGroupMemberSDKTypeEIP712 = ({ membersToAdd: MsgGroupMember[]; membersToDelete: string[]; }) => { - const res: Record> = cloneDeep( - MsgUpdateGroupMemberSDKTypeEIP712, - ); + const res: EIP712Msg = cloneDeep(MsgUpdateGroupMemberSDKTypeEIP712); if (membersToAdd.length > 0) { res.Msg1.push({ diff --git a/packages/chain-sdk/src/messages/utils.ts b/packages/chain-sdk/src/messages/utils.ts index c6aa1d81..c55fe282 100644 --- a/packages/chain-sdk/src/messages/utils.ts +++ b/packages/chain-sdk/src/messages/utils.ts @@ -3,6 +3,8 @@ import mapValues from 'lodash.mapvalues'; import sortBy from 'lodash.sortby'; import { MetaTxInfo } from '..'; +export type EIP712Msg = Record>; + export const typeWrapper = (type: string, msg: object) => { return { ...msg,