2022-08-26 03:32:50 +02:00
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
|
|
|
|
|
|
import {
|
2022-09-13 12:28:33 +02:00
|
|
|
IAccount,
|
2022-09-03 13:06:35 +02:00
|
|
|
ICircuit, ICircuitState, IGlobalState,
|
2022-08-26 03:32:50 +02:00
|
|
|
} from '@src/model'
|
|
|
|
|
import { tools } from '@store/Modules/tools'
|
|
|
|
|
import translate from '@src/globalroutines/util'
|
|
|
|
|
|
|
|
|
|
import * as Types from '@src/store/Api/ApiTypes'
|
|
|
|
|
import { useGlobalStore } from '@store/globalStore'
|
|
|
|
|
import { serv_constants } from '@store/Modules/serv_constants'
|
|
|
|
|
import { Api } from '@api'
|
|
|
|
|
import { toolsext } from '@store/Modules/toolsext'
|
|
|
|
|
import { static_data } from '@src/db/static_data'
|
2022-09-14 11:31:48 +02:00
|
|
|
import { useUserStore } from '@store/UserStore'
|
2022-08-26 03:32:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
import { shared_consts } from '@/common/shared_vuejs'
|
|
|
|
|
import { costanti } from '@costanti'
|
|
|
|
|
|
|
|
|
|
import globalroutines from '../globalroutines/index'
|
|
|
|
|
|
|
|
|
|
export const useCircuitStore = defineStore('CircuitStore', {
|
2022-09-03 13:06:35 +02:00
|
|
|
state: (): ICircuitState => ({
|
2022-08-26 03:32:50 +02:00
|
|
|
listcircuits: []
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
getters: {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
actions: {
|
2022-09-13 12:28:33 +02:00
|
|
|
getRemainingCoinsToSend(account: IAccount) {
|
2022-09-14 11:31:48 +02:00
|
|
|
if (account)
|
|
|
|
|
return tools.roundDec2(account.saldo + account.fidoConcesso)
|
|
|
|
|
else
|
|
|
|
|
return 0
|
2022-09-13 12:28:33 +02:00
|
|
|
},
|
|
|
|
|
getMaxCoinsToSend(account: IAccount) {
|
2022-09-14 11:31:48 +02:00
|
|
|
if (account)
|
|
|
|
|
return tools.roundDec2(account.qta_maxConcessa - account.saldo)
|
|
|
|
|
else
|
|
|
|
|
return 0
|
|
|
|
|
},
|
|
|
|
|
getSaldoByCircuitId(circuitId: string): number {
|
|
|
|
|
const userStore = useUserStore()
|
|
|
|
|
const account = userStore.my.profile.useraccounts.find((rec: IAccount) => rec.circuitId === circuitId)
|
|
|
|
|
if (account)
|
|
|
|
|
return account.saldo
|
|
|
|
|
else
|
|
|
|
|
return 0
|
2022-09-13 12:28:33 +02:00
|
|
|
},
|
2022-09-03 13:06:35 +02:00
|
|
|
|
2022-08-26 03:32:50 +02:00
|
|
|
async loadCircuits() {
|
|
|
|
|
return Api.SendReq('/users/circuits', 'POST', null)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
return res.data
|
|
|
|
|
}).catch((error) => {
|
|
|
|
|
return {}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
})
|