Skip to content

Commit

Permalink
fix: padRight should be used for hex strings representing encoded bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
JeneaVranceanu committed Jul 29, 2024
1 parent 12ee2e8 commit 9a12476
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/components/shared/ContractFunction.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { decodeData, MethodType } from '@/helpers/functionUtils'
import { reactive, computed, watch, onMounted } from 'vue'
import { toWei, Unit, padLeft, numberToHex } from 'web3-utils'
import { toWei, Unit, padLeft, padRight, numberToHex } from 'web3-utils'
import ParamField from './ParamField.vue'
import useWeb3Connection from '@/compositions/useWeb3Connection'
import ERC725 from '@erc725/erc725.js'
Expand Down Expand Up @@ -179,7 +179,7 @@ const makeBytes = (value: string, type: string) => {
return padLeft(hex, bytesCount * 2)
}
if (/^0x[0-9a-f]*$/i.test(value)) {
return padLeft(value, bytesCount * 2)
return padRight(value, bytesCount * 2)
}
if (/^\w*(:.*,.*)?$/.test(value)) {
const items = (value || '').split(',')
Expand Down
11 changes: 9 additions & 2 deletions src/components/shared/ParamField.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<script setup lang="ts">
import { reactive, computed, watch } from 'vue'
import { toWei, Unit, padLeft, numberToHex, hexToNumber } from 'web3-utils'
import {
toWei,
Unit,
padLeft,
padRight,
numberToHex,
hexToNumber,
} from 'web3-utils'
import ERC725, { ERC725JSONSchema } from '@erc725/erc725.js'
import LSPSelect from '@/components/shared/LSPSelect.vue'
import { BN } from 'bn.js'
Expand Down Expand Up @@ -377,7 +384,7 @@ const makeBytes32 = (index: number, force = false) => {
}
}
if (/^0x[0-9a-f]*$/i.test(item.value)) {
return padLeft(item.value, 64)
return padRight(item.value, 64)
}
if (/^[0-9]*$/.test(item.value)) {
return padLeft(item.value, 64)
Expand Down

0 comments on commit 9a12476

Please sign in to comment.