mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-08-15 17:50:54 -04:00
add documentation to add new grpc api functions (#21)
This commit is contained in:
parent
27404bd5b9
commit
20a5f52e67
3 changed files with 15 additions and 2 deletions
|
@ -30,7 +30,7 @@ Running the [top-level API tests](./src/HavenoDaemon.test.tsx) is a great way to
|
||||||
Example: `docker run --rm -it -v ~/git/haveno-ui-poc/config/envoy.test.yaml:/envoy.test.yaml -p 8080:8080 -p 8081:8081 envoyproxy/envoy-dev:8a2143613d43d17d1eb35a24b4a4a4c432215606 -c /envoy.test.yaml`
|
Example: `docker run --rm -it -v ~/git/haveno-ui-poc/config/envoy.test.yaml:/envoy.test.yaml -p 8080:8080 -p 8081:8081 envoyproxy/envoy-dev:8a2143613d43d17d1eb35a24b4a4a4c432215606 -c /envoy.test.yaml`
|
||||||
5. `npm install`
|
5. `npm install`
|
||||||
6. Modify test config as needed in [HavenoDaemon.test.tsx](./src/HavenoDaemon.test.tsx).
|
6. Modify test config as needed in [HavenoDaemon.test.tsx](./src/HavenoDaemon.test.tsx).
|
||||||
7. `npm test` to run all tests or `npm run test -- -t 'my test'` to run tests by name
|
7. `npm test` to run all tests or `npm run test -- -t 'my test'` to run tests by name.
|
||||||
|
|
||||||
## How to Update the Protobuf Client
|
## How to Update the Protobuf Client
|
||||||
|
|
||||||
|
|
13
docs/adding_api_functions.md
Normal file
13
docs/adding_api_functions.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# How to add and test new gRPC API functions in Haveno
|
||||||
|
|
||||||
|
1. Follow [instructions](https://github.com/haveno-dex/haveno-ui-poc#run-tests) to run Haveno's existing API tests successfully.
|
||||||
|
2. Define the new service or message in Haveno's [protobuf definition](../proto/src/main/proto/grpc.proto).
|
||||||
|
3. Clean and build Haveno after modifying the protobuf definition: `make clean && make`
|
||||||
|
4. Implement the new service in Haveno's backend, following existing patterns.<br>
|
||||||
|
For example, the gRPC function to get offers is implemented by [`GrpcServer`](https://github.com/haveno-dex/haveno/blob/master/daemon/src/main/java/bisq/daemon/grpc/GrpcServer.java) > [`GrpcOffersService.getOffers(...)`](https://github.com/haveno-dex/haveno/blob/b761dbfd378faf49d95090c126318b419af7926b/daemon/src/main/java/bisq/daemon/grpc/GrpcOffersService.java#L104) > [`CoreApi.getOffers(...)`](https://github.com/haveno-dex/haveno/blob/b761dbfd378faf49d95090c126318b419af7926b/core/src/main/java/bisq/core/api/CoreApi.java#L128) > [`CoreOffersService.getOffers(...)`](https://github.com/haveno-dex/haveno/blob/b761dbfd378faf49d95090c126318b419af7926b/core/src/main/java/bisq/core/api/CoreOffersService.java#L126) > [`OfferBookService.getOffers()`](https://github.com/haveno-dex/haveno/blob/b761dbfd378faf49d95090c126318b419af7926b/core/src/main/java/bisq/core/offer/OfferBookService.java#L193).
|
||||||
|
5. Build Haveno: `make`
|
||||||
|
6. Follow [instructions](https://github.com/haveno-dex/haveno-ui-poc#how-to-update-the-protobuf-client) to update the protobuf client in haveno-ui-poc.
|
||||||
|
7. Add the corresponding typescript method(s) to [HavenoDaemon.tsx](https://github.com/haveno-dex/haveno-ui-poc/blob/master/src/HavenoDaemon.tsx) with clear and concise documentation.
|
||||||
|
8. Add clean and comprehensive tests to [HavenoDaemon.test.tsx](https://github.com/haveno-dex/haveno-ui-poc/blob/master/src/HavenoDaemon.test.tsx), following existing patterns.
|
||||||
|
9. Verify the tests with `npm run test -- -t 'my test'` to run tests by name and `npm test` to run all tests together.
|
||||||
|
10. Open a pull request for review.
|
|
@ -56,7 +56,7 @@ class HavenoDaemon {
|
||||||
* @param {string} currencyCode - currency code to get the price of
|
* @param {string} currencyCode - currency code to get the price of
|
||||||
* @return {number} the current market price of the given currency code as a ratio, e.g. XMR/ETH
|
* @return {number} the current market price of the given currency code as a ratio, e.g. XMR/ETH
|
||||||
*/
|
*/
|
||||||
async getPrice(currencyCode: string) {
|
async getPrice(currencyCode: string): Promise<number> {
|
||||||
let that = this;
|
let that = this;
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
that._priceClient.getMarketPrice(new MarketPriceRequest().setCurrencyCode(currencyCode), {password: that._password}, function(err: grpcWeb.Error, response: MarketPriceReply) {
|
that._priceClient.getMarketPrice(new MarketPriceRequest().setCurrencyCode(currencyCode), {password: that._password}, function(err: grpcWeb.Error, response: MarketPriceReply) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue