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

Balance Symbol not work #4

Open
enri90 opened this issue Dec 31, 2024 · 0 comments
Open

Balance Symbol not work #4

enri90 opened this issue Dec 31, 2024 · 0 comments

Comments

@enri90
Copy link

enri90 commented Dec 31, 2024

The balance function does not allow all currencies associated with an account to be displayed.
Only the first currency in the list is visible

[
    {
        "balance": "50 BANQTA"
    },
    {
        "balance": "50 MSOURCE"
    }
]


 await contract.table("accounts", accountName).get("MSOURCE",
 
 {
    "balance": "50 BANQTA"
}
 async balance(
        accountName: NameType,
        symbolCode?: Asset.SymbolCodeType,
        contractName?: NameType
    ): Promise<Asset> {
        const contract = await this.getContract(contractName)
        const table = contract.table('accounts', accountName)

        let tableQuery

        if (symbolCode) {
            tableQuery = table.get(String(symbolCode), {index_position: 'primary'})
        } else {
            tableQuery = table.get()
        }

        return tableQuery
            .then((accountBalance) => {
                if (!accountBalance) {
                    throw new Error(`Account ${accountName} does not exist.`)
                }

                if (symbolCode && !accountBalance.balance.symbol.code.equals(symbolCode)) {
                    throw new Error(`Symbol '${symbolCode}' does not exist.`)
                }

                return accountBalance?.balance
            })
            .catch((err) => {
                throw new Error(`Failed to fetch balance for ${accountName}: ${err}`)
            })
    }

Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant