My first contribution to utopian - Added Features to swapsteem

in #utopian-io5 years ago (edited)

Repository

https://github.com/nirvanaitsolutions/swapsteem

New Features

This contribution is related to utopian Task Request. As a solution to this Issue I had to implement custom pricing feature to users while posting trade, along with ability to perform actions like Edit, Pause and Delete on the existing trade listing as per the mentioned task request.

The task was divided into 4 features as mentioned in the TR.

  1. In the PostTrade component, we need an additional input box for "margin" field which will accept values from -25% to 25 percentage. The price of such a listing will be determined as
    Ad_Price = Current Price of Coin + Current Price of Coin * margin
    If the margin is set negative, the price will be lower than the current price and vice versa.
    To implement this feature, we had to ask the user for their desired margin over the current market price while creating a new trade listing. Further, we had to display the existing and new trade listings with the revised margin. The formula for calculation of the effective price is also mentioned above.

To complete this feature, I had to uncomment and reuse the existing margin field in the form, while making sure that the selected margin is correctly being sent to the server. Also, I had to change the existing calculatePrice() in the Buy, Sell and Purchase components to align the prices with the desired margin selected by the user as below.

calculatePrice(from: string, to: string, margin: number) {
    if (from == "STEEM") {
      switch (to) {
        case "USD":
          return Math.round(this.steemPrice[0] * (1 + margin / 100) * 100) / 100;
        case "INR":
          return Math.round(this.steemPrice[1] * (1 + margin / 100) * 100) / 100;
        case "KRW":
          return Math.round(this.steemPrice[2] * (1 + margin / 100) * 100) / 100;
      }

    }
    else if (from == "SBD") {
      switch (to) {
        case "USD":
          return Math.round(this.sbdPrice[0] * (1 + margin / 100) * 100) / 100;
        case "INR":
          return Math.round(this.sbdPrice[1] * (1 + margin / 100) * 100) / 100;
        case "KRW":
          return Math.round(this.steemPrice[2] * (1 + margin / 100) * 100) / 100;
      }

    }
  }

This was done in the commit Implement price with margin values.

You can see the added margin field and updated prices in below screenshots.
Post A Trade: image.png

Home : image.png

Buy : image.png

Sell : image.png

To implement the Rest of the 3 features I replaced the existng non functional View/Edit button in the profile component with an Anctions Dropdown to enable any of the above features via a single click as explained below.

  1. Ability to VIEW/EDIT a trade listing
    This feature enables users to view and edit their previously created listing from their profile page. This can be done via the Edit button. This was done in the commit Implement ad update feature

  2. Ability to PAUSE a trade listing
    This feature enables users to PAUSE their trade listing if they are not available to trade. Other users will not be able to see the trade listing until it's resumed. This can be done via the Pause button. This was done in the commit Add pipe for ad_status

  3. Ability to DELETE a trade listing
    This feature enables a user to DELETE their trade listing if they are no longer willing to trade.This can be done via the Delete button. This was done in the commit Implement ad delete and pause feature

 viewAds(ad: AdvertisementResponse) {
    this.router.navigate(['post-trade/' + ad._id]);
  }

  pauseAd(id: string) {
    this.apiSer.pauseAd(id).subscribe(res => {
      this.openAds = this.apiSer.getAdsByUser(this.userData.name);
    });
  }

  deleteAd(id: string) {
    this.apiSer.deleteAd(id).subscribe(res => {
      this.openAds = this.apiSer.getAdsByUser(this.userData.name);
    });
  }

And in API Service I had to add POST calls to the API.

deleteAd(id: string): Observable<AdvertisementRequest> {
    // httpOptions.headers = httpOptions.headers.append("Authorization",this.token.access_token);
    return this._http.delete<AdvertisementRequest>(`http://swapsteem-api.herokuapp.com/advertisements/${id}`);
  }

  pauseAd(id: string): Observable<AdvertisementRequest> {
    // httpOptions.headers = httpOptions.headers.append("Authorization",this.token.access_token);
    return this._http.put<AdvertisementRequest>(`http://swapsteem-api.herokuapp.com/advertisements/${id}`, JSON.stringify({
      ad_status: "pause"
    }));
  }

You can see the added dropdown and buttons in below screenshot.
Profile : image.png

GitHub Account

https://github.com/Shubh1692

GitHub Account

https://github.com/bunyy

Proof of Work

Merged Pull Requests

  1. https://github.com/nirvanaitsolutions/swapsteem/pull/27
  2. https://github.com/nirvanaitsolutions/swapsteem/pull/28

Screenshot for Account ownership for Subh1692
image.png

Screenshot for Account ownership for bunyy
image.png

Sort:  
  • Good article, well documented with code samples and explanations of coding choices. Maybe you're just missing an intro graphic to your post.
  • There is no new comments in the code, do add some next time.
  • I had a had time finding the production website, here it is for reference: http://swapsteem.online/

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for your review, @helo! Keep up the good work!


Welcome to Steemit @svijay1692!

I wish you much success and hope you find Steemit to be as rewarding and informative as I have.

Here are some links you might find useful.
Your stats on SteemNow
Your stats on SteemWorld
Your stats on SteemD
How does Steemit actually work?

Oh yea, I have upvoted you and followed you. Many blessings!

Great work @svijay1692! Looking forward for more contributions from you. And welcome to utopian :)

Posted using Partiko Android

Welcome svijay1692!
eSteem is the application that improves your experience here. We have Mobile application for Android and iOS users. We also have developed Surfer Desktop application that helps you to gain new followers and stay connected with your friends, unique features - notifications, bookmarks, favorites, drafts, and more.
We reward our users with encouragement upvotes as well as monthly giveaways rewarding Spotlight top users and active Discord users.
Learn more: https://esteem.app
Join our discord: https://discord.gg/8eHupPq

Congratulations @svijay1692! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You published your First Post
You made your First Vote
You got a First Vote
You received more than 10 upvotes. Your next target is to reach 50 upvotes.

Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

SteemWhales has officially moved to SteemitBoard Ranking
SteemitBoard - Witness Update

Support SteemitBoard's project! Vote for its witness and get one more award!

Hi @svijay1692!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @svijay1692!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.034
BTC 63475.77
ETH 3117.23
USDT 1.00
SBD 3.94