Skip to content

Commit

Permalink
Tx fail fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vrrayz committed Jun 21, 2023
1 parent e7517cc commit e7d4b82
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { OpeningMetadata } from '@joystream/metadata-protobuf'
import BN from 'bn.js'

import { Api } from '@/api'
import { BN_ZERO } from '@/common/constants'
import { BN_ZERO, JOY_DECIMAL_PLACES } from '@/common/constants'
import { createType } from '@/common/model/createType'
import { metadataToBytes } from '@/common/model/JoystreamNode'
import { last } from '@/common/utils'
Expand All @@ -14,6 +15,15 @@ const idToRuntimeId = (id: string): number => Number(last(id.split('-')))

const getWorkingGroupParam = (groupId: GroupIdName | undefined) => groupId && GroupIdToGroupParam[groupId]

const mapAccountsAndAmounts = (input: string | undefined) => {
const decimals = new BN(10).pow(new BN(JOY_DECIMAL_PLACES))
return input?.split(';\n').map((item) => {
const [address, amount] = item.split(',')
const formattedAmount = new BN(amount).mul(decimals)
return { amount: formattedAmount, account: address }
})
}

export const getSpecificParameters = async (
api: Api,
specifics: Omit<AddNewProposalForm, 'triggerAndDiscussion' | 'stakingAccount' | 'proposalDetails'>
Expand All @@ -30,9 +40,9 @@ export const getSpecificParameters = async (
}
case 'fundingRequest': {
return createType('PalletProposalsCodexProposalDetails', {
FundingRequest: [
{ amount: specifics?.fundingRequest?.amount, account: specifics?.fundingRequest?.account?.address },
],
FundingRequest: specifics?.fundingRequest?.payMultiple
? mapAccountsAndAmounts(specifics?.fundingRequest?.accountsAndAmounts)
: [{ amount: specifics?.fundingRequest?.amount, account: specifics?.fundingRequest?.account?.address }],
})
}
case 'runtimeUpgrade': {
Expand Down

0 comments on commit e7d4b82

Please sign in to comment.