Skip to content

Commit

Permalink
fix: missing fungible token balances (#1432)
Browse files Browse the repository at this point in the history
Signed-off-by: --replace <[email protected]>
  • Loading branch information
timi-codes authored Oct 21, 2024
1 parent f1d20e7 commit 8807097
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/components/token/TokenCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ import BlobValue from "@/components/values/BlobValue.vue";
import {TokenInfoCache} from "@/utils/cache/TokenInfoCache";
import {makeTokenName, makeTokenSymbol} from "@/schemas/HederaUtils";
import TokenAmount from "@/components/values/TokenAmount.vue";
import {BalanceCache} from "@/utils/cache/BalanceCache";
import {TokenType} from "@/schemas/HederaSchemas";
import { TokenRelationshipCache } from "@/utils/cache/TokenRelationshipCache";
export enum TokenCellItem {
tokenName = "tokenName",
Expand Down Expand Up @@ -90,15 +90,15 @@ export default defineComponent({
onMounted(() => infoLookup.mount())
onBeforeUnmount(() => infoLookup.unmount())
const balanceLookup = BalanceCache.instance.makeLookup(accountId)
const balanceLookup = TokenRelationshipCache.instance.makeLookup(accountId)
onMounted(() => balanceLookup.mount())
onBeforeUnmount(() => balanceLookup.unmount())
const tokenBalance = computed(() => {
let result
if (balanceLookup.entity.value !== null && balanceLookup.entity.value.balances.length >= 1) {
if (balanceLookup.entity.value !== null) {
result = null
for (const t of balanceLookup.entity.value.balances[0].tokens) {
for (const t of balanceLookup.entity.value) {
if (t.token_id === props.tokenId) {
result = t.balance
break
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/Mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2262,6 +2262,27 @@ export const SAMPLE_TOKEN_ASSOCIATIONS = {
}
}

export const SAMPLE_TOKEN_ASSOCIATIONS_2 = {
"tokens": [{
"automatic_association": false,
"balance": 2342647909,
"created_timestamp": SAMPLE_TOKEN_ASSOCIATE_TRANSACTION.consensus_timestamp,
"freeze_status": "UNFROZEN",
"kyc_status": "NOT_APPLICABLE",
"token_id": SAMPLE_ASSOCIATED_TOKEN.token_id
}, {
"automatic_association": false,
"balance": 31669471,
"created_timestamp": "1671648712.150557003",
"freeze_status": "UNFROZEN",
"kyc_status": "NOT_APPLICABLE",
"token_id": SAMPLE_ASSOCIATED_TOKEN_2.token_id
}],
"links": {
next: null
}
}

//
// Account inspired from: https://mainnet-public.mirrornode.hedera.com/api/v1/accounts/0.0.730631
//
Expand Down
36 changes: 8 additions & 28 deletions tests/unit/account/TokensSection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import {
SAMPLE_ASSOCIATED_TOKEN,
SAMPLE_ASSOCIATED_TOKEN_2,
SAMPLE_NFTS,
SAMPLE_NONFUNGIBLE
SAMPLE_NONFUNGIBLE,
SAMPLE_TOKEN_ASSOCIATIONS_2
} from "../Mocks";
import MockAdapter from "axios-mock-adapter";
import Oruga from "@oruga-ui/oruga-next";
Expand All @@ -53,29 +54,6 @@ describe("TokensSection.vue", () => {
SAMPLE_ASSOCIATED_TOKEN_2
]
}
const SAMPLE_BALANCES = {
"timestamp": "1646728200.821070000",
"balances": [
{
"account": accountId,
"balance": 42,
"tokens": [
{
"token_id": SAMPLE_ASSOCIATED_TOKEN.token_id,
"balance": 420000
},
{
"token_id": SAMPLE_ASSOCIATED_TOKEN_2.token_id,
"balance": 4200000000
},
{
"token_id": "0.0.34332104",
"balance": 0
}
]
}
]
}

const mock = new MockAdapter(axios);

Expand All @@ -93,8 +71,9 @@ describe("TokensSection.vue", () => {
mock.onGet(matcher4).reply(200, SAMPLE_ASSOCIATED_TOKEN)
const matcher5 = "/api/v1/tokens/" + SAMPLE_ASSOCIATED_TOKEN_2.token_id
mock.onGet(matcher5).reply(200, SAMPLE_ASSOCIATED_TOKEN_2)
const matcher6 = "/api/v1/balances"
mock.onGet(matcher6).reply(200, SAMPLE_BALANCES)
const matcher6 = "/api/v1/accounts/" + SAMPLE_ACCOUNT.account + "/tokens?limit=100"
mock.onGet(matcher6).reply(200, SAMPLE_TOKEN_ASSOCIATIONS_2)

})

afterAll(() => {
Expand Down Expand Up @@ -182,9 +161,10 @@ describe("TokensSection.vue", () => {

const associationsTable = tokensSection.get("#fungibleTable")
expect(associationsTable.find('thead').text()).toBe("Token Name Symbol Balance")
console.log(associationsTable.find('tbody').text())
expect(associationsTable.find('tbody').text()).toBe(
"0.0.34332104" + "HSUITE" + "HSuite" + "42.0000" +
"0.0.49292859" + "Token SymbolA7" + "TokenA7" + "42.00000000"
"0.0.34332104" + "HSUITE" + "HSuite" + "234,264.7909" +
"0.0.49292859" + "Token SymbolA7" + "TokenA7" + "0.31669471"
)

wrapper.unmount()
Expand Down

0 comments on commit 8807097

Please sign in to comment.