Skip to content

Commit

Permalink
fix nonce draft bug
Browse files Browse the repository at this point in the history
  • Loading branch information
clbrge committed Apr 23, 2023
1 parent c02ca7d commit dbcd8d4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import localizedFormat from 'dayjs/plugin/localizedFormat.js'
dayjs.extend(localizedFormat)

// toHexString(toHexString(any) = (toHexString(any)
export const toHexString = (any) => {
return '0x' + BigInt(any).toString(16)
export const toHexString = (any, size) => {
const hexString = BigInt(any).toString(16)
if (size) return '0x' + hexString.padStart(size, '0')
return '0x' + hexString
}

export const formatDate = (date) => {
Expand Down
14 changes: 14 additions & 0 deletions src/routes/(app)/project/[address]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import Project from '$components/Project.svelte'
import project from '$stores/project.js'
//import { toHexString } from '$lib/utils.js'
export let data
Expand All @@ -18,6 +19,17 @@
const endpoint = import.meta.env.VITE_SPRINGBOK_ENDPOINT
const gateway = `${endpoint}/ipfs/`
const test = () => {
// // Object { draftNonce: 1 }
// const draftNonce = 1
// //toHexString(draftNonce)
// //invalid BytesLike value (argument="value", value="0x1", code=INVALID_ARGUMENT, version=6.3.0)
// console.log(draftNonce)
//
// const address = toHexString(draftNonce, 40)
// console.log(address)
}
</script>

<Project {p} />
Expand Down Expand Up @@ -78,6 +90,8 @@
href={(p.uri || '').replace('ipfs://', gateway)}>{p.uri}</a>
</p>
<p><a href="/i/special/foxwallet/">foxwallet</a></p>

<button class="button" on:click={test}>test</button>
</article>
{/if}

Expand Down
3 changes: 1 addition & 2 deletions src/stores/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,7 @@ const createStore = () => {

const createDraft = async (data) => {
console.log({ draftNonce })
const address = ethers.zeroPadValue(toHexString(draftNonce), 20)
localStorage.setItem(draftNonceKey(), ++draftNonce)
const address = toHexString(draftNonce, 40)
updateDraft(address, data)
return address
}
Expand Down

0 comments on commit dbcd8d4

Please sign in to comment.