-
Notifications
You must be signed in to change notification settings - Fork 2
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: 83 add cosmos service: add query and tx clients #96
Conversation
- make all cosm.js dependencies 0.27.1
- no we only have 166 webpack warnings but no errors
- @cosmjs dependencies and the cosmjs-types dependency do not publish source code, so attempting to read the source code to generate maps will cause warnings - other ways to deal with this: - have a postinstall script to clone git source libraries into their needed destinations for source map generation to work correctly - ignore specifically these errors in Webpack: "Failed to parse source map" & "Error: ENOENT: no such file or directory" - this is difficult to do in create-react-app so perhaps it would be better to switch to a create-next-app or Vite build system
This reverts commit 3462564.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I thought that the requests would be part of this commit (fetching the ticks, etc.)
src/lib/web3/api.ts
Outdated
interface QueryClientOptions { | ||
addr?: string; | ||
} | ||
|
||
const queryClient = async ({ | ||
addr = REACT_APP__REST_API, | ||
}: QueryClientOptions = {}) => { | ||
return new Api({ baseUrl: addr }); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a bit too complicated
If we don't add any more attributes something like would be a lot simpler
interface QueryClientOptions { | |
addr?: string; | |
} | |
const queryClient = async ({ | |
addr = REACT_APP__REST_API, | |
}: QueryClientOptions = {}) => { | |
return new Api({ baseUrl: addr }); | |
}; | |
const queryClient = (addr = REACT_APP__REST_API ) => { | |
return new Api({ baseUrl: addr }); | |
} |
If we do, I think somewhat spreading the defaults would make a more readable (maybe a tiny bit)
interface QueryClientOptions { | |
addr?: string; | |
} | |
const queryClient = async ({ | |
addr = REACT_APP__REST_API, | |
}: QueryClientOptions = {}) => { | |
return new Api({ baseUrl: addr }); | |
}; | |
const defaultOptions = { | |
addr: REACT_APP__REST_API | |
}; | |
const queryClient = (options = defaultOptions) => { | |
const { addr } = { ...defaultOptions, ...options }; | |
return new Api({ baseUrl: addr }); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved by pulling in the already generated ApiConfig
type with the baseUrl already predefined in d1729a5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, you might be able to simplify queryClient
src/lib/web3/api.ts
Outdated
const queryClient = async ({ | ||
baseUrl = REACT_APP__REST_API, | ||
baseApiParams, | ||
securityWorker, | ||
}: ApiConfig = {}) => { | ||
return new Api({ baseUrl, baseApiParams, securityWorker }); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't exactly the same, but I think you could just pass everything else as is, without having to care about the number of arguments being passed in
const queryClient = async ({ | |
baseUrl = REACT_APP__REST_API, | |
baseApiParams, | |
securityWorker, | |
}: ApiConfig = {}) => { | |
return new Api({ baseUrl, baseApiParams, securityWorker }); | |
}; | |
const queryClient = async (config: ApiConfig = {}) => { | |
return new Api({ ...config, baseUrl: config?.baseUrl ?? REACT_APP__REST_API }); | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, added a further simplification in 7f08a17
f5f9b12
to
7f08a17
Compare
## [0.1.8](v0.1.7...v0.1.8) (2022-07-25) ### Features * 83 add cosmos service: add query and tx clients ([#96](#96)) ([abafc31](abafc31))
🎉 This PR is included in version 0.1.8 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This PR adds an autogenerated
queryClient
and a semi-autogeneratedtxClient
with generated types from the Cosmos server, for easier using or queries and msgs from within components.