Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contract events for ui updates to pledge display #105

Merged
merged 27 commits into from
Jun 1, 2023

Conversation

sreuland
Copy link
Contributor

@sreuland sreuland commented Apr 28, 2023

Added contract events to the dapp examples. Demonstrating how to wire up events from a contract to the dapp, and some aspects of async, event driven application state changes.

Most of the aspects of subscribing to get events has been implemented as a reusable react provider in soroban-react/pr-26 and used here in the pledge components.

The pr changes the Pledged Amount at top of screen to be event driven, rest of app display state remains user request based. A short video demo's the effect, it shows two browser panels, both have dapp loaded and using the same rpc server and freighter wallet. Left side browser has no user interaction, but its Pledged Amount state will change as it receives contract events from the rpc server, while on the right side browser, the user initiates pledges(contract invocations).

Untitled.2.mp4

Closes soroban-tools:458
Closes #107

This is based on Soroban Preview 9

Copy link
Contributor

@paulbellamy paulbellamy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, code looks good. There's a dependency issue in the build, seems like, and it would be good to get the 0.5.1 version of the soroban-client dependency

contracts/crowdfund/src/events.rs Outdated Show resolved Hide resolved
contracts/crowdfund/src/lib.rs Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
contracts/token/soroban_token_spec.wasm Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
@tsachiherman tsachiherman added the soroban-scrum A label to make relevant issues appear in the Platform Scrum board. label May 2, 2023
@sreuland sreuland marked this pull request as ready for review May 26, 2023 04:16
@sreuland
Copy link
Contributor Author

after updating to all preview9 versions available, it seems close, am trying to run locally, seeing a problem with initialize.sh it's having issue invoking 'initialize` contract fn, running cli 0.8.0:

$ ./initialize.sh standalone
Using standalone network
Add the standalone network to cli client
Fund token-admin account from friendbot
Wrap the Stellar asset
Token wrapped succesfully with TOKEN_ID: 6b5be340632ae1b59e6730b610e4bfb3aa9bacb9c649feb926ac8959af3f714f
Build the crowdfund contract
cargo fmt --all
cargo build --target wasm32-unknown-unknown --no-default-features --release
    Finished release [optimized] target(s) in 0.21s
cd target/wasm32-unknown-unknown/release/ && \
		for i in *.wasm ; do \
			ls -l "$i"; \
		done
-rwxr-xr-x  1 5974 May 25 21:48 soroban_crowdfund_contract.wasm
Deploy the crowdfund contract
Contract deployed succesfully with ID: 9645a9aac1526834a3622b4556f36444054af68d55b9e16d3e8ffaaa5b4f19d6
Initialize the crowdfund contract
error: parsing argument token: value is not parseable to Some(
    Address,
)
Done

the token param on that fn call needs to be Address, it looks like cli just accept strkey format, not sure what to use from within script to convert the binary hex of token 6b5be340632ae1b59e6730b610e4bfb3aa9bacb9c649feb926ac8959af3f714f into a strkey C...

@Shaptic
Copy link
Contributor

Shaptic commented May 26, 2023

@sreuland you can use the SDK, e.g. SorobanClient.Address.contract(Buffer.from('6b5be340...', 'hex')) (something like that)

@Shaptic
Copy link
Contributor

Shaptic commented May 26, 2023

or for something more raw, you can use SorobanClient.StrKey.encodeContract(Buffer.from(...

@Shaptic
Copy link
Contributor

Shaptic commented May 26, 2023

@sreuland
Copy link
Contributor Author

@Shaptic , thanks for insight on the StrKey usage, I added a workaround based on that.

@sreuland
Copy link
Contributor Author

@Shaptic, @paulbellamy

I'm debugging an issue here with latest versions, getting TypeError: this._buffer.readBigInt64BE is not a function when trying to use fromXDR() from SorobanClient.xdr on simulation responses, able to replicate directly as:

let test = SorobanClient.xdr.ScVal.fromXDR(Buffer.from("AAAACgAAAAAAAAAAAAAAADuaygA=", 'base64'));

this works in node but from browser(using dist) get the error. seems like something is not getting included up the dependency tree by webpack, as it's gen'd xdr code packaged from dts-xdr->xdr-gen->stellar-base->soroban-client. any insights on this appreciated.

@sreuland
Copy link
Contributor Author

sreuland commented May 31, 2023

runtime looks stable, need to test pledges to confirm that area works before merging, will do that once freighter 5.0.2 comes out as pledges go through that as payments.

Copy link
Contributor

@paulbellamy paulbellamy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed two minor bugs, and a couple side-comments. But LGTM.

address_workaround.js Show resolved Hide resolved
quickstart.sh Show resolved Hide resolved
@Julian-dev28
Copy link
Contributor

Julian-dev28 commented Jun 1, 2023

Dockerfile still has RUN cargo install --locked --version 0.7.1 soroban-cli

Does this need to be updated RUN cargo install --locked --version 0.8.0 soroban-cli?

@sreuland
Copy link
Contributor Author

sreuland commented Jun 1, 2023

Dockerfile still has RUN cargo install --locked --version 0.7.1 soroban-cli

Does this need to be updated RUN cargo install --locked --version 0.8.0 soroban-cli?

@Julian-dev28 , I believe that ref for cli has been updated in pr change set - https://github.com/stellar/soroban-example-dapp/pull/105/files#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557R15

@sreuland sreuland merged commit 7615fd0 into stellar:main Jun 1, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
soroban-scrum A label to make relevant issues appear in the Platform Scrum board.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

soroban-example-dapp: add support for fees Update Example DApp for RPC: GetEvents
5 participants