fungible-systems / micro-stacks

Tiny libraries for building the next generation of Stacks apps.
https://micro-stacks.dev
MIT License
83 stars 14 forks source link

fix: return correct type for successful broadcasts #75

Closed hstove closed 2 years ago

hstove commented 2 years ago

In the latest micro-stacks, broadcastTransaction returns { txid: string }, but that's not the TypeScript type. You need to do funky workarounds when using this library in TS to get the result you want.

A different option is to actually return a string, which would also fix the issue (and be backwards compat with stacks.js?)

changeset-bot[bot] commented 2 years ago

🦋 Changeset detected

Latest commit: 7829721eff8c47d8554e11c29eddb72bc12fb23f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------------ | ----- | | micro-stacks | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

aulneau commented 2 years ago

hmm yeah there needs to be some updates, see https://github.com/hirosystems/stacks.js/blob/master/packages/transactions/src/builders.ts#L363

zone117x commented 2 years ago

It looks like this change does make micro-stacks match the behavior of stacks.js https://github.com/hirosystems/stacks.js/blob/fe831cf28d71de9410c81cfabe256fd511e9aa4d/packages/transactions/src/builders.ts#L449-L451

Looks like stacks.js transforms the response into an actual object from the rather odd string-quoted txid string returned by /v2/transaction.

aulneau commented 2 years ago

ah yes, @hstove can you do a minor change via changesets?

hstove commented 2 years ago

Thanks for the changeset + merge!

aviculturist commented 2 years ago

So now when you read the data from an onFinish callback, you end up having to do something like this:

const onFinish = useCallback(
    data => {
      const txid = data.txId.txid;

Can that be reduced to data.txid or data.txId?

aulneau commented 2 years ago

@aviculturist is that what you are currently experiencing?

based off the wallet code, that is not correct: https://github.com/hirosystems/stacks-wallet-web/blob/dev/src/app/common/transactions/broadcast-transaction.ts#L28

aviculturist commented 2 years ago

Yes, it's what I'm seeing in the data object with Hiro Wallet v3.0.0.

screenshot

.