Repository: CryptoBlades/cryptoblades
File: frontend/src/views/NftDisplay.vue (Vue)

Code before:
        text = window.location.href;
      document.body.appendChild(dummy);
      dummy.value = text;
      dummy.select();
      document.execCommand('copy');
      document.body.removeChild(dummy);
    },
    convertWeiToSkill(wei: string): string {
      return fromWeiEther(wei);
    },
    maxPrecisionSkill(listedPrice: string): string {
      return this.convertStringToDecimal(
        this.convertWeiToSkill(listedPrice),
        8
      );
    },
    convertStringToDecimal(val: string, maxDecimals: number) {
      return new BigNumber(val).toFixed(maxDecimals);
    },
    async purchaseNft() {
      this.marketOutcome = null;
      if (this.nftId === null) return;

      const price = await this.lookupNftPrice(this.nftId);
      if (price) {
        this.nftPrice = price;
      } else {
        return;
      }

      const skillChainPrice = this.convertStringToDecimal(
        this.convertWeiToSkill(price),
        2
      );
      const skillUIPrice = this.convertStringToDecimal(
        this.nftPriceInSkill(),
        2
      );

      if (skillChainPrice !== skillUIPrice) {
        (this as any).$dialog.notify.error(
          'The price of the listing has changed. Please refresh listing and try again'
        );
        return;
      }

      this.waitingMarketOutcome = true;

      const results: any = await this.purchaseMarketListing({
        nftContractAddr: this.contractAddress,
        tokenId: this.nftId,

Review comment (suggestion):
I need some clarification here. When purchasing we want to check if displayed price equals price on chain. Here you read price from chain and assign it to UI price to later on check if they are the same. This is confusing, because now they will always be the same even though they could be different before you reassigned UI price here.

I think in original Market we just do `if(!price) return;`

Code after:
        text = window.location.href;
      document.body.appendChild(dummy);
      dummy.value = text;
      dummy.select();
      document.execCommand('copy');
      document.body.removeChild(dummy);
    },
    convertWeiToSkill(wei: string): string {
      return fromWeiEther(wei);
    },
    maxPrecisionSkill(listedPrice: string): string {
      return this.convertStringToDecimal(
        this.convertWeiToSkill(listedPrice),
        8
      );
    },
    convertStringToDecimal(val: string, maxDecimals: number) {
      return new BigNumber(val).toFixed(maxDecimals);
    },
    async purchaseNft() {
      if (this.nftId === null) return;

      const price = await this.lookupNftPrice(this.nftId);
      if (!price) return;

      const skillChainPrice = this.convertStringToDecimal(
        this.convertWeiToSkill(price),
        2
      );
      const skillUIPrice = this.convertStringToDecimal(
        this.nftPriceInSkill(),
        2
      );

      if (skillChainPrice !== skillUIPrice) {
        (this as any).$dialog.notify.error(
          'The price of the listing has changed. Please refresh listing and try again'
        );
        return;
      }

      await this.purchaseMarketListing({
        nftContractAddr: this.contractAddress,
        tokenId: this.nftId,
        maxPrice: price,
      });

      await this.fetchAllMarketNftIds({
        nftContractAddr: this.contractAddress,
      });
      await this.fetchOwnerAddress();