Skip to content

Commit

Permalink
fix internal typescript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanchristo committed Jun 29, 2023
1 parent f5c3bea commit 96f220c
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions src/api/group.amino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PercentageDecisionPolicy,
ThresholdDecisionPolicy,
} from '@regen-network/api/src/codegen/cosmos/group/v1/types'
import { Any } from '@regen-network/api/src/codegen/google/protobuf/any'
import { Any, AnyAmino } from '@regen-network/api/src/codegen/google/protobuf/any'
import type {
MsgCreateGroupWithPolicy,
MsgCreateGroupWithPolicyAmino,
Expand Down Expand Up @@ -34,41 +34,39 @@ export const groupAminoConverters = {
decisionPolicy:
object !== null && object !== void 0 && object.decision_policy
? object.decision_policy.type === 'cosmos-sdk/PercentageDecisionPolicy'
? Any.fromPartial({
? (Any.fromPartial({
typeUrl: '/cosmos.group.v1.PercentageDecisionPolicy',
value: PercentageDecisionPolicy.encode(
PercentageDecisionPolicy.fromPartial(
PercentageDecisionPolicy.fromAmino(object.decision_policy?.value),
),
).finish(),
})
: Any.fromPartial({
}) as ThresholdDecisionPolicy & PercentageDecisionPolicy & Any) // TODO
: (Any.fromPartial({
typeUrl: '/cosmos.group.v1.ThresholdDecisionPolicy',
value: ThresholdDecisionPolicy.encode(
ThresholdDecisionPolicy.fromPartial(
ThresholdDecisionPolicy.fromAmino(object.decision_policy?.value),
),
).finish(),
})
: undefined,
}) as ThresholdDecisionPolicy & PercentageDecisionPolicy & Any)
: (Any.fromPartial({
typeUrl: 'not implemented',
}) as ThresholdDecisionPolicy & PercentageDecisionPolicy & Any), // TODO
}
console.log('fromAmino output', output)
return output // TODO: typescript errors
return output
},
toAmino: (message: MsgCreateGroupWithPolicy): MsgCreateGroupWithPolicyAmino => {
console.log('toAmino input', message)
const output = {
admin: message.admin,
members: message.members
? message.members.map((e) => (e ? MemberRequest.toAmino(e) : undefined))
? message.members.map((e) => MemberRequest.toAmino(e))
: [],
group_metadata: message.groupMetadata ? message.groupMetadata : undefined,
group_policy_metadata: message.groupPolicyMetadata
? message.groupPolicyMetadata
: undefined,
group_policy_as_admin: message.groupPolicyAsAdmin
? message.groupPolicyAsAdmin
: undefined,
group_metadata: message.groupMetadata,
group_policy_metadata: message.groupPolicyMetadata,
group_policy_as_admin: message.groupPolicyAsAdmin,
decision_policy: message.decisionPolicy
? message.decisionPolicy.typeUrl === '/cosmos.group.v1.PercentageDecisionPolicy'
? {
Expand All @@ -86,7 +84,7 @@ export const groupAminoConverters = {
: undefined,
}
console.log('toAmino output', output)
return output // TODO: typescript errors
return output
},
},
'/cosmos.group.v1.MsgSubmitProposal': {
Expand All @@ -112,29 +110,32 @@ export const groupAminoConverters = {
const output = {
group_policy_address: message.groupPolicyAddress,
proposers: message.proposers ? message.proposers.map((e) => e) : [],
metadata: message.metadata ? message.metadata : undefined,
metadata: message.metadata,
// messages: message.messages ? message.messages.map(e => e ? Any.toAmino(e) : undefined) : [],
messages: message.messages
? message.messages.map((msg) => {
switch (msg.typeUrl) {
// TODO: unable to resolve type URL cosmos-sdk/MsgSend: tx parse error
// TODO: unable to resolve type URL cosmos-sdk/MsgSend
case '/cosmos.bank.v1beta1.MsgSend':
return {
type_url: 'cosmos-sdk/MsgSend',
type: 'cosmos-sdk/MsgSend',
type_url: 'cosmos-sdk/MsgSend', // TODO: unable to resolve type URL (empty)
value: MsgSend.toAmino(MsgSend.decode(msg?.value)),
}
// TODO: unable to resolve type URL not implemented: tx parse error
} as AnyAmino
// TODO: unable to resolve type URL not implemented
default:
return {
type_url: 'not implemented',
}
type: 'not implemented',
type_url: 'not implemented', // TODO: unable to resolve type URL (empty)
value: undefined,
} as AnyAmino
}
})
: [],
exec: message.exec,
}
console.log('toAmino output', output)
return output // TODO: typescript errors
return output
},
},
'/cosmos.group.v1.MsgVote': {
Expand All @@ -146,20 +147,22 @@ export const groupAminoConverters = {
voter: object.voter,
option: object.option !== null && object.option !== undefined ? object.option : 0,
metadata: object.metadata,
exec: object.exec !== null && object.exec !== undefined ? object.exec : 0,
}
console.log('fromAmino output', output)
return output
},
toAmino: (message: MsgVote): MsgVoteAmino => {
console.log('toAmino input', message)
const output = {
proposal_id: message.proposalId ? message.proposalId.toString() : undefined,
proposal_id: message.proposalId.toString(),
voter: message.voter,
option: message.option,
metadata: message.metadata ? message.metadata : undefined,
metadata: message.metadata,
exec: message.exec,
}
console.log('toAmino output', output)
return output // TODO: typescript errors
return output
},
},
}

0 comments on commit 96f220c

Please sign in to comment.