vue-3-useeosiowallet
Advanced tools
Comparing version 0.2.9 to 0.2.10
@@ -35,3 +35,3 @@ import { computed, ref } from 'vue'; | ||
export const isAuthenticated = ref(false); | ||
export const userBalance = ref(0); | ||
export const userBalance = ref({ balance: 0, symbol: '' }); | ||
export const setup = async (appName, chains) => { | ||
@@ -52,2 +52,6 @@ if (!appName) | ||
throw new Error('Fetch Balance Failed: Account param is undefined.'); | ||
const balance = { | ||
balance: 0, | ||
symbol: selectedChain.value.id.toUpperCase(), | ||
}; | ||
const tablePayload = { | ||
@@ -62,8 +66,11 @@ code: 'eosio.token', | ||
if (!result.rows.length) | ||
return 0; | ||
return Number(result.rows[0].balance); | ||
return balance; | ||
balance.balance = Number(result.rows[0].balance); | ||
return balance; | ||
}; | ||
export const refreshUserBalance = async () => { | ||
const result = await fetchAccountBalance('jxlangheimer'); | ||
console.log(result); | ||
if (!username.value) | ||
throw new Error('Refresh User Balance: Username undefined.'); | ||
userBalance.value = await fetchAccountBalance(username.value); | ||
return userBalance.value; | ||
}; | ||
@@ -70,0 +77,0 @@ export const transact = async (actions) => { |
@@ -37,6 +37,9 @@ import { JsonRpc } from 'eosjs'; | ||
export declare const isAuthenticated: import("vue").Ref<boolean>; | ||
export declare const userBalance: import("vue").Ref<number>; | ||
export declare const userBalance: import("vue").Ref<{ | ||
balance: number; | ||
symbol: string; | ||
}>; | ||
export declare const setup: (appName: string, chains: EosioChain[]) => Promise<void>; | ||
export declare const fetchAccountBalance: (account: string) => Promise<number>; | ||
export declare const refreshUserBalance: () => Promise<void>; | ||
export declare const fetchAccountBalance: (account: string) => Promise<TokenBalance>; | ||
export declare const refreshUserBalance: () => Promise<TokenBalance>; | ||
export declare const transact: (actions: any[]) => Promise<string>; | ||
@@ -43,0 +46,0 @@ export declare const login: (walletId: Wallet) => Promise<string>; |
{ | ||
"name": "vue-3-useeosiowallet", | ||
"version": "0.2.9", | ||
"version": "0.2.10", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -60,3 +60,3 @@ import { computed, ref } from 'vue'; | ||
export const userBalance = ref<number>(0); | ||
export const userBalance = ref<TokenBalance>({ balance: 0, symbol: '' }); | ||
@@ -74,3 +74,3 @@ export const setup = async (appName: string, chains: EosioChain[]): Promise<void> => { | ||
export const fetchAccountBalance = async (account: string): Promise<number> => { | ||
export const fetchAccountBalance = async (account: string): Promise<TokenBalance> => { | ||
if (!isSetup.value) | ||
@@ -80,2 +80,7 @@ throw new Error('Fetch Balance Failed: Eosio wallet setup required. Please use setup() function first.'); | ||
const balance: TokenBalance = { | ||
balance: 0, | ||
symbol: selectedChain.value.id.toUpperCase(), | ||
}; | ||
const tablePayload = { | ||
@@ -90,10 +95,14 @@ code: 'eosio.token', | ||
const result = await rpc.get_table_rows(tablePayload); | ||
if (!result.rows.length) return 0; | ||
if (!result.rows.length) return balance; | ||
return Number(result.rows[0].balance); | ||
balance.balance = Number(result.rows[0].balance); | ||
return balance; | ||
}; | ||
export const refreshUserBalance = async (): Promise<void> => { | ||
const result = await fetchAccountBalance('jxlangheimer'); | ||
console.log(result); | ||
export const refreshUserBalance = async (): Promise<TokenBalance> => { | ||
if (!username.value) throw new Error('Refresh User Balance: Username undefined.'); | ||
userBalance.value = await fetchAccountBalance(username.value); | ||
return userBalance.value; | ||
}; | ||
@@ -100,0 +109,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
50407
825