-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
592 changed files
with
267,840 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
vue/src/store/generated/cosmonaut/loan/cosmonaut.loan.loan/index.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Loan } from "./module/types/loan/loan"; | ||
export { Loan }; | ||
declare const _default; | ||
export default _default; |
299 changes: 299 additions & 0 deletions
299
vue/src/store/generated/cosmonaut/loan/cosmonaut.loan.loan/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,299 @@ | ||
import { txClient, queryClient, MissingWalletError } from './module'; | ||
// @ts-ignore | ||
import { SpVuexError } from '@starport/vuex'; | ||
import { Loan } from "./module/types/loan/loan"; | ||
export { Loan }; | ||
async function initTxClient(vuexGetters) { | ||
return await txClient(vuexGetters['common/wallet/signer'], { | ||
addr: vuexGetters['common/env/apiTendermint'] | ||
}); | ||
} | ||
async function initQueryClient(vuexGetters) { | ||
return await queryClient({ | ||
addr: vuexGetters['common/env/apiCosmos'] | ||
}); | ||
} | ||
function mergeResults(value, next_values) { | ||
for (let prop of Object.keys(next_values)) { | ||
if (Array.isArray(next_values[prop])) { | ||
value[prop] = [...value[prop], ...next_values[prop]]; | ||
} | ||
else { | ||
value[prop] = next_values[prop]; | ||
} | ||
} | ||
return value; | ||
} | ||
function getStructure(template) { | ||
let structure = { fields: [] }; | ||
for (const [key, value] of Object.entries(template)) { | ||
let field = {}; | ||
field.name = key; | ||
field.type = typeof value; | ||
structure.fields.push(field); | ||
} | ||
return structure; | ||
} | ||
const getDefaultState = () => { | ||
return { | ||
Loan: {}, | ||
LoanAll: {}, | ||
_Structure: { | ||
Loan: getStructure(Loan.fromPartial({})), | ||
}, | ||
_Subscriptions: new Set(), | ||
}; | ||
}; | ||
// initial state | ||
const state = getDefaultState(); | ||
export default { | ||
namespaced: true, | ||
state, | ||
mutations: { | ||
RESET_STATE(state) { | ||
Object.assign(state, getDefaultState()); | ||
}, | ||
QUERY(state, { query, key, value }) { | ||
state[query][JSON.stringify(key)] = value; | ||
}, | ||
SUBSCRIBE(state, subscription) { | ||
state._Subscriptions.add(subscription); | ||
}, | ||
UNSUBSCRIBE(state, subscription) { | ||
state._Subscriptions.delete(subscription); | ||
} | ||
}, | ||
getters: { | ||
getLoan: (state) => (params = { params: {} }) => { | ||
if (!params.query) { | ||
params.query = null; | ||
} | ||
return state.Loan[JSON.stringify(params)] ?? {}; | ||
}, | ||
getLoanAll: (state) => (params = { params: {} }) => { | ||
if (!params.query) { | ||
params.query = null; | ||
} | ||
return state.LoanAll[JSON.stringify(params)] ?? {}; | ||
}, | ||
getTypeStructure: (state) => (type) => { | ||
return state._Structure[type].fields; | ||
} | ||
}, | ||
actions: { | ||
init({ dispatch, rootGetters }) { | ||
console.log('Vuex module: cosmonaut.loan.loan initialized!'); | ||
if (rootGetters['common/env/client']) { | ||
rootGetters['common/env/client'].on('newblock', () => { | ||
dispatch('StoreUpdate'); | ||
}); | ||
} | ||
}, | ||
resetState({ commit }) { | ||
commit('RESET_STATE'); | ||
}, | ||
unsubscribe({ commit }, subscription) { | ||
commit('UNSUBSCRIBE', subscription); | ||
}, | ||
async StoreUpdate({ state, dispatch }) { | ||
state._Subscriptions.forEach(async (subscription) => { | ||
try { | ||
await dispatch(subscription.action, subscription.payload); | ||
} | ||
catch (e) { | ||
throw new SpVuexError('Subscriptions: ' + e.message); | ||
} | ||
}); | ||
}, | ||
async QueryLoan({ commit, rootGetters, getters }, { options: { subscribe, all } = { subscribe: false, all: false }, params: { ...key }, query = null }) { | ||
try { | ||
const queryClient = await initQueryClient(rootGetters); | ||
let value = (await queryClient.queryLoan(key.id)).data; | ||
commit('QUERY', { query: 'Loan', key: { params: { ...key }, query }, value }); | ||
if (subscribe) | ||
commit('SUBSCRIBE', { action: 'QueryLoan', payload: { options: { all }, params: { ...key }, query } }); | ||
return getters['getLoan']({ params: { ...key }, query }) ?? {}; | ||
} | ||
catch (e) { | ||
throw new SpVuexError('QueryClient:QueryLoan', 'API Node Unavailable. Could not perform query: ' + e.message); | ||
} | ||
}, | ||
async QueryLoanAll({ commit, rootGetters, getters }, { options: { subscribe, all } = { subscribe: false, all: false }, params: { ...key }, query = null }) { | ||
try { | ||
const queryClient = await initQueryClient(rootGetters); | ||
let value = (await queryClient.queryLoanAll(query)).data; | ||
while (all && value.pagination && value.pagination.nextKey != null) { | ||
let next_values = (await queryClient.queryLoanAll({ ...query, 'pagination.key': value.pagination.nextKey })).data; | ||
value = mergeResults(value, next_values); | ||
} | ||
commit('QUERY', { query: 'LoanAll', key: { params: { ...key }, query }, value }); | ||
if (subscribe) | ||
commit('SUBSCRIBE', { action: 'QueryLoanAll', payload: { options: { all }, params: { ...key }, query } }); | ||
return getters['getLoanAll']({ params: { ...key }, query }) ?? {}; | ||
} | ||
catch (e) { | ||
throw new SpVuexError('QueryClient:QueryLoanAll', 'API Node Unavailable. Could not perform query: ' + e.message); | ||
} | ||
}, | ||
async sendMsgApproveLoan({ rootGetters }, { value, fee = [], memo = '' }) { | ||
try { | ||
const txClient = await initTxClient(rootGetters); | ||
const msg = await txClient.msgApproveLoan(value); | ||
const result = await txClient.signAndBroadcast([msg], { fee: { amount: fee, | ||
gas: "200000" }, memo }); | ||
return result; | ||
} | ||
catch (e) { | ||
if (e == MissingWalletError) { | ||
throw new SpVuexError('TxClient:MsgApproveLoan:Init', 'Could not initialize signing client. Wallet is required.'); | ||
} | ||
else { | ||
throw new SpVuexError('TxClient:MsgApproveLoan:Send', 'Could not broadcast Tx: ' + e.message); | ||
} | ||
} | ||
}, | ||
async sendMsgRepayLoan({ rootGetters }, { value, fee = [], memo = '' }) { | ||
try { | ||
const txClient = await initTxClient(rootGetters); | ||
const msg = await txClient.msgRepayLoan(value); | ||
const result = await txClient.signAndBroadcast([msg], { fee: { amount: fee, | ||
gas: "200000" }, memo }); | ||
return result; | ||
} | ||
catch (e) { | ||
if (e == MissingWalletError) { | ||
throw new SpVuexError('TxClient:MsgRepayLoan:Init', 'Could not initialize signing client. Wallet is required.'); | ||
} | ||
else { | ||
throw new SpVuexError('TxClient:MsgRepayLoan:Send', 'Could not broadcast Tx: ' + e.message); | ||
} | ||
} | ||
}, | ||
async sendMsgLiquidateLoan({ rootGetters }, { value, fee = [], memo = '' }) { | ||
try { | ||
const txClient = await initTxClient(rootGetters); | ||
const msg = await txClient.msgLiquidateLoan(value); | ||
const result = await txClient.signAndBroadcast([msg], { fee: { amount: fee, | ||
gas: "200000" }, memo }); | ||
return result; | ||
} | ||
catch (e) { | ||
if (e == MissingWalletError) { | ||
throw new SpVuexError('TxClient:MsgLiquidateLoan:Init', 'Could not initialize signing client. Wallet is required.'); | ||
} | ||
else { | ||
throw new SpVuexError('TxClient:MsgLiquidateLoan:Send', 'Could not broadcast Tx: ' + e.message); | ||
} | ||
} | ||
}, | ||
async sendMsgRequestLoan({ rootGetters }, { value, fee = [], memo = '' }) { | ||
try { | ||
const txClient = await initTxClient(rootGetters); | ||
const msg = await txClient.msgRequestLoan(value); | ||
const result = await txClient.signAndBroadcast([msg], { fee: { amount: fee, | ||
gas: "200000" }, memo }); | ||
return result; | ||
} | ||
catch (e) { | ||
if (e == MissingWalletError) { | ||
throw new SpVuexError('TxClient:MsgRequestLoan:Init', 'Could not initialize signing client. Wallet is required.'); | ||
} | ||
else { | ||
throw new SpVuexError('TxClient:MsgRequestLoan:Send', 'Could not broadcast Tx: ' + e.message); | ||
} | ||
} | ||
}, | ||
async sendMsgCancelLoan({ rootGetters }, { value, fee = [], memo = '' }) { | ||
try { | ||
const txClient = await initTxClient(rootGetters); | ||
const msg = await txClient.msgCancelLoan(value); | ||
const result = await txClient.signAndBroadcast([msg], { fee: { amount: fee, | ||
gas: "200000" }, memo }); | ||
return result; | ||
} | ||
catch (e) { | ||
if (e == MissingWalletError) { | ||
throw new SpVuexError('TxClient:MsgCancelLoan:Init', 'Could not initialize signing client. Wallet is required.'); | ||
} | ||
else { | ||
throw new SpVuexError('TxClient:MsgCancelLoan:Send', 'Could not broadcast Tx: ' + e.message); | ||
} | ||
} | ||
}, | ||
async MsgApproveLoan({ rootGetters }, { value }) { | ||
try { | ||
const txClient = await initTxClient(rootGetters); | ||
const msg = await txClient.msgApproveLoan(value); | ||
return msg; | ||
} | ||
catch (e) { | ||
if (e == MissingWalletError) { | ||
throw new SpVuexError('TxClient:MsgApproveLoan:Init', 'Could not initialize signing client. Wallet is required.'); | ||
} | ||
else { | ||
throw new SpVuexError('TxClient:MsgApproveLoan:Create', 'Could not create message: ' + e.message); | ||
} | ||
} | ||
}, | ||
async MsgRepayLoan({ rootGetters }, { value }) { | ||
try { | ||
const txClient = await initTxClient(rootGetters); | ||
const msg = await txClient.msgRepayLoan(value); | ||
return msg; | ||
} | ||
catch (e) { | ||
if (e == MissingWalletError) { | ||
throw new SpVuexError('TxClient:MsgRepayLoan:Init', 'Could not initialize signing client. Wallet is required.'); | ||
} | ||
else { | ||
throw new SpVuexError('TxClient:MsgRepayLoan:Create', 'Could not create message: ' + e.message); | ||
} | ||
} | ||
}, | ||
async MsgLiquidateLoan({ rootGetters }, { value }) { | ||
try { | ||
const txClient = await initTxClient(rootGetters); | ||
const msg = await txClient.msgLiquidateLoan(value); | ||
return msg; | ||
} | ||
catch (e) { | ||
if (e == MissingWalletError) { | ||
throw new SpVuexError('TxClient:MsgLiquidateLoan:Init', 'Could not initialize signing client. Wallet is required.'); | ||
} | ||
else { | ||
throw new SpVuexError('TxClient:MsgLiquidateLoan:Create', 'Could not create message: ' + e.message); | ||
} | ||
} | ||
}, | ||
async MsgRequestLoan({ rootGetters }, { value }) { | ||
try { | ||
const txClient = await initTxClient(rootGetters); | ||
const msg = await txClient.msgRequestLoan(value); | ||
return msg; | ||
} | ||
catch (e) { | ||
if (e == MissingWalletError) { | ||
throw new SpVuexError('TxClient:MsgRequestLoan:Init', 'Could not initialize signing client. Wallet is required.'); | ||
} | ||
else { | ||
throw new SpVuexError('TxClient:MsgRequestLoan:Create', 'Could not create message: ' + e.message); | ||
} | ||
} | ||
}, | ||
async MsgCancelLoan({ rootGetters }, { value }) { | ||
try { | ||
const txClient = await initTxClient(rootGetters); | ||
const msg = await txClient.msgCancelLoan(value); | ||
return msg; | ||
} | ||
catch (e) { | ||
if (e == MissingWalletError) { | ||
throw new SpVuexError('TxClient:MsgCancelLoan:Init', 'Could not initialize signing client. Wallet is required.'); | ||
} | ||
else { | ||
throw new SpVuexError('TxClient:MsgCancelLoan:Create', 'Could not create message: ' + e.message); | ||
} | ||
} | ||
}, | ||
} | ||
}; |
Oops, something went wrong.