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

feat(wip): removed signer from viewMethods by dropping NAJ account.ViewFunction #35

Merged
merged 5 commits into from
Jul 24, 2024

Conversation

jaswinder6991
Copy link
Collaborator

In this PR, I remove account.ViewFunction to drop dependency on using a Signer for view methods. We instead use the providers from near-api-js to write a utility method for viewFunction.

Description

Type of change

  • [x ] 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🏗️ Build configuration (CI configuration, scaffolding etc.)
  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • [x ] 📝 Documentation update(s)
  • 📦 Dependency update(s)
  • 👩🏽‍💻 Improve developer experience
  • ⚡ Improve performance
  • [x ] ✨ New feature (non-breaking change which adds functionality)
  • [x ] ♻ Refactor
  • ⏪ Revert changes
  • [ x] 🧪 New tests or updates to existing tests

@jaswinder6991 jaswinder6991 marked this pull request as ready for review July 23, 2024 10:02
@kieranroneill kieranroneill linked an issue Jul 23, 2024 that may be closed by this pull request
Copy link
Collaborator

@kieranroneill kieranroneill left a comment

Choose a reason for hiding this comment

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

Some minor conventions that are not gamechangers. However, the use of Buffer in the viewFunction will not work in browsers without a polyfill.

I recommendation would be to use individual packages (base64/utf8) from https://www.stablelib.com/index.html to do all the decoding/encoding.

src/constants/Config.ts Outdated Show resolved Hide resolved
src/controllers/Social.ts Outdated Show resolved Hide resolved
src/utils/rpcQueries/viewFunction.ts Outdated Show resolved Hide resolved
src/utils/rpcQueries/viewFunction.ts Outdated Show resolved Hide resolved
@@ -30,7 +30,7 @@ export default async function viewFunction({
request_type: 'call_function',
account_id: contractId,
method_name: method,
args_base64: Buffer.from(JSON.stringify(args)).toString('base64'),
args_base64: btoa(JSON.stringify(args)),
Copy link
Collaborator

@kieranroneill kieranroneill Jul 24, 2024

Choose a reason for hiding this comment

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

This will fail in Node.js context as btoa is only in the browser (ahhh JavaScript).

Suggestion: you could wrap it in a try/catch and fallback to Buffer.toString('base64).

Copy link
Collaborator

@kieranroneill kieranroneill left a comment

Choose a reason for hiding this comment

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

Approved ✅

@@ -17,6 +17,14 @@ function parseJsonFromRawResponse(response: Uint8Array): ViewFunctionResult {
return JSON.parse(new TextDecoder().decode(response));
}

function base64Encode(str: string): string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@jaswinder6991 jaswinder6991 merged commit a57edc4 into beta Jul 24, 2024
5 checks passed
@jaswinder6991 jaswinder6991 deleted the 34-remove-signer-for-view-methods branch July 24, 2024 16:07
github-actions bot pushed a commit that referenced this pull request Jul 24, 2024
# [1.1.0-beta.1](v1.0.1...v1.1.0-beta.1) (2024-07-24)

### Features

* **wip:** removed signer from viewMethods by dropping NAJ account.ViewFunction ([#35](#35)) ([a57edc4](a57edc4))
@kieranroneill
Copy link
Collaborator

🎉 This PR is included in version 1.1.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@kieranroneill kieranroneill added the 🚀 released To the moon! label Jul 24, 2024
@jaswinder6991
Copy link
Collaborator Author

@race-of-sloths

@race-of-sloths
Copy link

race-of-sloths commented Jul 25, 2024

@jaswinder6991 Thank you for your contribution! Your pull request is now a part of the Race of Sloths!
New Sloth joined the Race! Welcome!

Shows profile picture for the author of the PR

Current status: executed

@jaswinder6991 check out your results on the Race of Sloths Leaderboard! and in the profile

What is the Race of Sloths

Race of Sloths is a friendly competition where you can participate in challenges and compete with other open-source contributors within your normal workflow

For contributors:

  • Tag @race-of-sloths inside your pull requests
  • Wait for the maintainer to review and score your pull request
  • Check out your position in the Leaderboard
  • Keep weekly and monthly streaks to reach higher positions
  • Boast your contributions with a dynamic picture of your Profile

For maintainers:

  • Score pull requests that participate in the Race of Sloths
  • Engage contributors with fair scoring and fast responses so they keep their streaks
  • Promote the Race to the point where the Race starts promoting you
  • Grow the community of your contributors

Feel free to check our website for additional details!

Bot commands
  • For contributors
    • Include a PR: @race-of-sloths include to enter the Race with your PR
  • For maintainers:
    • Assign points: @race-of-sloths score [1/2/3/5/8/13] to award points based on your assessment.
    • Reject this PR: @race-of-sloths exclude to send this PR back to the drawing board.
    • Exclude repo: @race-of-sloths pause to stop bot activity in this repo until @race-of-sloths unpause command is called

@race-of-sloths
Copy link

🔄 The PR has been merged.

Important

This pull request is a part of the Race of Sloths and has not been scored yet. Scoring will close in 24 hours! 🕰️

@race-of-sloths
Copy link

✅ PR is finalized!

Your contribution is much appreciated with a final score of 0!
You have received 10 (0 base + 10 weekly bonus) Sloth points for this contribution

Another weekly streak completed, well done @jaswinder6991! To keep your weekly streak and get another bonus make pull request next week! Looking forward to see you in race-of-sloths

jaswinder6991 added a commit that referenced this pull request Aug 19, 2024
* feat(wip): removed signer from viewMethods by dropping NAJ account.ViewFunction (#35)

* feat(wip): removed signer from viewMethods by dropping accounts.ViewFunction

* chore: fixed docs and removed comments

* chore: fixed linting issues

* fix: removed the use of Buffer as it won't work in browser environments

* fix: put try/catch for btoa

* chore(release): 1.1.0-beta.1

# [1.1.0-beta.1](v1.0.1...v1.1.0-beta.1) (2024-07-24)

### Features

* **wip:** removed signer from viewMethods by dropping NAJ account.ViewFunction ([#35](#35)) ([a57edc4](a57edc4))

* feat: remove near-api-js account object dependency from change functions (#38)

* refactor: remove dependency on near-api-js account and connection objects from change functions

* test: update tests to use new network initialization

* chore: squash

* docs: amend docs to use new initailaization

* docs: update docs to use the new signer object and fix broken links

* build(lint): fix linting errors

* chore: squash

* refactor: convert signer to account because signer is icky

* chore(release): 1.1.0-beta.2

# [1.1.0-beta.2](v1.1.0-beta.1...v1.1.0-beta.2) (2024-07-25)

### Features

* remove near-api-js account object dependency from change functions ([#38](#38)) ([134e463](134e463))

* fix: required deposit fix when available storage is higher than needed (#40)

* fix: required deposit fix when available storage is higher than needed

* chore: fixed lint error

* chore(release): 1.1.0-beta.3

# [1.1.0-beta.3](v1.1.0-beta.2...v1.1.0-beta.3) (2024-07-30)

### Bug Fixes

* required deposit fix when available storage is higher than needed ([#40](#40)) ([99f9e8d](99f9e8d))

* feat: adding api server support for read methods (#33)

* feat: adding api server support for read methods

* feat(wip): added more args to get and introduced keys method

* chore: fixed merge issues

* feat: added index() function and docs for all api server changes

* docs: fix docs build

* chore(release): 1.1.0-beta.4

# [1.1.0-beta.4](v1.1.0-beta.3...v1.1.0-beta.4) (2024-08-01)

### Features

* adding api server support for read methods ([#33](#33)) ([dc53b30](dc53b30))

* feat: aded transformActions utility and exposed all utils (#42)

feat: added transformActions utility and exposed all utils

* chore(release): 1.1.0-beta.5

# [1.1.0-beta.5](v1.1.0-beta.4...v1.1.0-beta.5) (2024-08-05)

### Features

* aded transformActions utility and exposed all utils ([#42](#42)) ([bfc9072](bfc9072))

---------

Co-authored-by: nearbuilder <tech@nearbuilders.org>
Co-authored-by: Kieran O'Neill <hello@kieranoneill.com>
github-actions bot pushed a commit that referenced this pull request Aug 19, 2024
# [1.1.0](v1.0.1...v1.1.0) (2024-08-19)

### Features

* wallet support for frontend apps and API server methods ([#43](#43)) ([83bb3a6](83bb3a6)), closes [#35](#35) [#35](#35) [#38](#38) [#38](#38) [#40](#40) [#40](#40) [#33](#33) [#33](#33) [#42](#42) [#42](#42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 released To the moon!
Projects
None yet
3 participants