|
| 1 | +import type { DynamicGlobalProperties, ExtendedAccount } from "@hiveio/dhive"; |
| 2 | +import { type Account } from "~/schema/accounts.ts"; |
| 3 | +import { balanceToMoney, vestsToHive } from "~/schema/utils.ts"; |
| 4 | + |
| 5 | +const adaptAccount = ( |
| 6 | + account: ExtendedAccount, |
| 7 | + params: DynamicGlobalProperties |
| 8 | +): Account => { |
| 9 | + const jsonMetadata = JSON.parse(account.posting_json_metadata); |
| 10 | + |
| 11 | + return { |
| 12 | + id: account.id.toString(), |
| 13 | + name: account.name, |
| 14 | + created: new Date(account.created), |
| 15 | + wallet: { |
| 16 | + hive: { |
| 17 | + liquid: balanceToMoney(account.balance as string, 3)!, |
| 18 | + frozen: vestsToHive(account.vesting_shares as string, params) |
| 19 | + }, |
| 20 | + hbd: { |
| 21 | + liquid: balanceToMoney(account.hbd_balance as string, 3)!, |
| 22 | + frozen: balanceToMoney(account.savings_hbd_balance as string, 3)! |
| 23 | + } |
| 24 | + }, |
| 25 | + postCount: account.post_count, |
| 26 | + profile: { |
| 27 | + name: jsonMetadata.profile.name, |
| 28 | + about: jsonMetadata.profile.about, |
| 29 | + coverImage: jsonMetadata.profile.cover_image, |
| 30 | + profileImage: jsonMetadata.profile.profile_image, |
| 31 | + website: jsonMetadata.profile.website, |
| 32 | + location: jsonMetadata.profile.location |
| 33 | + } |
| 34 | + }; |
| 35 | +}; |
| 36 | + |
| 37 | +export { adaptAccount }; |
0 commit comments