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

Update Signer.ts #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/Signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
import { IConsole, makeConsole, makeOptions } from '@waves/client-logs';
import { fetchBalanceDetails } from '@waves/node-api-js/cjs/api-node/addresses';
import { fetchAssetsBalance } from '@waves/node-api-js/cjs/api-node/assets';
import { fetchAssetsAddressLimit } from '@waves/node-api-js/cjs/api-node/assets';
import wait from '@waves/node-api-js/cjs/tools/transactions/wait';
import broadcast from '@waves/node-api-js/cjs/tools/transactions/broadcast';
import getNetworkByte from '@waves/node-api-js/cjs/tools/blocks/getNetworkByte';
Expand Down Expand Up @@ -287,6 +288,53 @@ export class Signer {
]).then(([waves, assets]) => [waves, ...assets]);
}

/**
* Get NFT Balance
*/
@ensureProvider
@checkAuth
public getNftBalance(): Promise<Array<Balance>> {
return Promise.all([
fetchBalanceDetails(
this._options.NODE_URL,
this._userData!.address,
).then((data) => ({
assetId: 'WAVES',
assetName: 'Waves',
decimals: 8,
amount: String(data.available),
isMyAsset: false,
tokens: Number(data.available) * Math.pow(10, 8),
sponsorship: null,
isSmart: false,
})),
fetchAssetsAddressLimit(
Copy link
Contributor

Choose a reason for hiding this comment

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

Limit - required parameter

this._options.NODE_URL,
this._userData!.address,
).then((data) =>
data.balances.map((item) => ({
assetId: item.assetId,
assetName: item.issueTransaction.name,
Copy link
Contributor

Choose a reason for hiding this comment

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

IssueTransaction field can be null

decimals: item.issueTransaction.decimals,
amount: String(item.balance),
isMyAsset:
item.issueTransaction.sender ===
this._userData!.address,
tokens:
item.balance *
Math.pow(10, item.issueTransaction.decimals),
isSmart: !!item.issueTransaction.script,
sponsorship:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be error with big number. We use @waves/bignumber for that

item.sponsorBalance != null &&
item.sponsorBalance > Math.pow(10, 8) &&
(item.minSponsoredAssetFee || 0) < item.balance
? item.minSponsoredAssetFee
: null,
})),
),
]).then(([waves, assets]) => [waves, ...assets]);
}

/**
* Получаем информацию о пользователе
*
Expand Down