8000 fix: Template updates by clockworkgr · Pull Request #825 · ignite/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Template updates #825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 4 additions & 3 deletions starport/pkg/cosmosgen/templates/js/index.ts.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// THIS FILE IS GENERATED AUTOMATICALLY. DO NOT MODIFY.

import { coins, StdFee } from "@cosmjs/launchpad";
import { StdFee } from "@cosmjs/launchpad";
import { SigningStargateClient } from "@cosmjs/stargate";
import { Registry, OfflineSigner, EncodeObject, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { Api } from "./rest";
Expand All @@ -24,7 +24,8 @@ interface TxClientOptions {
}

interface SignAndBroadcastOptions {
fee: StdFee
fee: StdFee,
memo?: string
}

const txClient = async (wallet: OfflineSigner, { addr: addr }: TxClientOptions = { addr: "http://localhost:26657" }) => {
Expand All @@ -34,7 +35,7 @@ const txClient = async (wallet: OfflineSigner, { addr: addr }: TxClientOptions =
const { address } = (await wallet.getAccounts())[0];

return {
signAndBroadcast: (msgs: EncodeObject[], { fee: fee }: SignAndBroadcastOptions = { fee: defaultFee }) => client.signAndBroadcast(address, msgs, fee),
signAndBroadcast: (msgs: EncodeObject[], { fee=defaultFee, memo=null }: SignAndBroadcastOptions) => memo?client.signAndBroadcast(address, msgs, fee,memo):client.signAndBroadcast(address, msgs, fee),
{{ range .Module.Msgs }}{{ camelCase .Name }}: (data: {{ .Name }}): EncodeObject => ({ typeUrl: "/{{ .URI }}", value: data }),
{{ end }}
};
Expand Down
22 changes: 13 additions & 9 deletions starport/pkg/cosmosgen/templates/vuex/root/index.ts.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{ end }}

export default {
{{ range . }}{{ .FullName }}: load({{ .FullName }}, 'chain/{{ .FullPath }}'),
{{ range . }}{{ .FullName }}: load({{ .FullName }}, '{{ .Path }}'),
{{ end }}
}

Expand All @@ -18,13 +18,17 @@ function load(mod, fullns) {
store.registerModule(ns, { namespaced: true })
}
}
store.registerModule(fullnsLevels, mod)
store.subscribe((mutation) => {
if (mutation.type == 'chain/common/env/INITIALIZE_WS_COMPLETE') {
store.dispatch(fullns+ '/init', null, {
root: true
})
}
})
if (store.hasModule(fullnsLevels)) {
throw new Error('Duplicate module name detected: '+ fullnsLevels.pop())
}else{
store.registerModule(fullnsLevels, mod)
store.subscribe((mutation) => {
if (mutation.type == 'common/env/INITIALIZE_WS_COMPLETE') {
store.dispatch(fullns+ '/init', null, {
root: true
})
}
})
}
}
}
75 changes: 56 additions & 19 deletions starport/pkg/cosmosgen/templates/vuex/store/index.ts.tpl
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { txClient, queryClient } from './module'
// @ts-ignore
import { SpVuexError } from '@starport/vuex'

{{ range .Module.Types }}import { {{ .Name }} } from "./module/types/{{ resolveFile .FilePath }}"
{{ end }}

async function initTxClient(vuexGetters) {
return await txClient(vuexGetters['chain/common/wallet/signer'], {
addr: vuexGetters['chain/common/env/apiTendermint']
return await txClient(vuexGetters['common/wallet/signer'], {
addr: vuexGetters['common/env/apiTendermint']
})
}

async function initQueryClient(vuexGetters) {
return await queryClient({
addr: vuexGetters['chain/common/env/apiCosmos']
addr: vuexGetters['common/env/apiCosmos']
})
}

Expand All @@ -28,9 +30,7 @@ function getStructure(template) {

const getDefaultState = () => {
return {
{{ range .Module.Queries }}get{{ .Name }}: (state) => (params = {}) => {
return state.Post[JSON.stringify(params)] ?? {}
},
{{ range .Module.Queries }}{{ .Name }}: {},
{{ end }}
_Structure: {
{{ range .Module.Types }}{{ .Name }}: getStructure({{ .Name }}.fromPartial({})),
Expand Down Expand Up @@ -62,7 +62,10 @@ export default {
},
getters: {
{{ range .Module.Queries }}get{{ .Name }}: (state) => (params = {}) => {
return state.Post[JSON.stringify(params)] ?? {}
if (!(<any> params).query) {
(<any> params).query=null
}
return state.{{ .Name }}[JSON.stringify(params)] ?? {}
},
{{ end }}
getTypeStructure: (state) => (type) => {
Expand All @@ -72,8 +75,8 @@ export default {
actions: {
init({ dispatch, rootGetters }) {
console.log('init')
if (rootGetters['chain/common/env/client']) {
rootGetters['chain/common/env/client'].on('newblock', () => {
if (rootGetters['common/env/client']) {
rootGetters['common/env/client'].on('newblock', () => {
dispatch('StoreUpdate')
})
}
Expand All @@ -89,24 +92,58 @@ export default {
dispatch(subscription.action, subscription.payload)
})
},
{{ range .Module.Queries }}async {{ .FullName }}({ commit, rootGetters }, { subscribe = false, ...key }) {
{{ range .Module.Queries }}async {{ .FullName }}({ commit, rootGetters, getters }, { options: { subscribe = false , all = false}, params: {...key}, query=null }) {
try {
const value = (await (await initQueryClient(rootGetters)).{{ camelCase .FullName }}.apply(null, Object.values(key))).data
commit('QUERY', { query: 'Post', key, value })
if (subscribe) commit('SUBSCRIBE', { action: 'QueryPost', payload: key })

let value = query?(await (await initQueryClient(rootGetters)).{{ camelCase .FullName }}({{ range $i,$a :=.HTTPAnnotations.URLParams}} key.{{$a}}, {{end}} query)).data:(await (await initQueryClient(rootGetters)).{{ camelCase .FullName }}({{ range $i,$a :=.HTTPAnnotations.URLParams}}{{ if (gt $i 0)}}, {{ end}} key.{{$a}} {{end}})).data
{{ if .HTTPAnnotations.URLHasQuery}}
while (all && (<any> value).pagination && (<any> value).pagination.nextKey!=null) {
let next_values=(await (await initQueryClient(rootGetters)).{{ camelCase .FullName }}({{ range $i,$a :=.HTTPAnnotations.URLParams}} key.{{$a}}, {{end}}{...query, 'pagination.key':(<any> value).pagination.nextKey})).data
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]
}
}
}
{{ end }}
commit('QUERY', { query: '{{ .Name }}', key: { params: {...key}, query}, value })
if (subscribe) commit('SUBSCRIBE', { action: '{{ .FullName }}', payload: { options: { all }, params: {...key},query }})
return getters['get{{.Name }}']( { params: {...key}, query}) ?? {}
} catch (e) {
console.log('Query Failed: API node unavailable')
console.error(new SpVuexError('QueryClient:{{ .FullName }}', 'API Node Unavailable. Could not perform query.'))
return {}
}
},
{{ end }}
{{ range .Module.Msgs }}async {{ .Name }}({ rootGetters }, { value }) {
{{ end }}
{{ range .Module.Msgs }}async send{{ .Name }}({ rootGetters }, { value, fee, memo }) {
try {
const msg = await (await initTxClient(rootGetters)).{{ camelCase .Name }}(value)
await (await initTxClient(rootGetters)).signAndBroadcast([msg])
const result = await (await initTxClient(rootGetters)).signAndBroadcast([msg], {fee: { amount: fee,
gas: "200000" }, memo})
return result
} catch (e) {
throw 'Failed to broadcast transaction: ' + e
if (e.toString()=='wallet is required') {
throw new SpVuexError('TxClient:{{ .Name }}:Init', 'Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:{{ .Name }}:Send', 'Could not broadcast Tx.')
}
}
},
{{ end }}
{{ end }}
{{ range .Module.Msgs }}async {{ .Name }}({ rootGetters }, { value }) {
try {
const msg = await (await initTxClient(rootGetters)).{{ camelCase .Name }}(value)
return msg
} catch (e) {
if (e.toString()=='wallet is required') {
throw new SpVuexError('TxClient:{{ .Name }}:Init', 'Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:{{ .Name }}:Create', 'Could not create message.')
}
}
},
{{ end }}
}
}
2 changes: 1 addition & 1 deletion starport/services/chain/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (c *Chain) buildProto(ctx context.Context) error {

// generate Vuex code as well if it is enabled.
if conf.Client.Vuex.Path != "" {
storeRootPath := filepath.Join(c.app.Path, conf.Client.Vuex.Path, "chain")
storeRootPath := filepath.Join(c.app.Path, conf.Client.Vuex.Path, "generated")
options = append(options,
cosmosgen.WithVuexGeneration(
enableThirdPartyModuleCodegen,
Expand Down
2 changes: 1 addition & 1 deletion starport/services/scaffolder/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (s *Scaffolder) protoc(projectPath, gomodPath string, version cosmosver.Maj

// generate Vuex code as well if it is enabled.
if conf.Client.Vuex.Path != "" {
storeRootPath := filepath.Join(projectPath, conf.Client.Vuex.Path, "chain")
storeRootPath := filepath.Join(projectPath, conf.Client.Vuex.Path, "generated")
options = append(options,
cosmosgen.WithVuexGeneration(
false,
Expand Down
39 changes: 8 additions & 31 deletions starport/templates/app/stargate/vue/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,7 @@
<SpWallet ref="wallet" v-on:dropdown-opened="$refs.menu.closeDropdown()" />
<SpLayout>
<template v-slot:sidebar>
<SpSidebar
v-on:sidebar-open="sidebarOpen = true"
v-on:sidebar-close="sidebarOpen = false"
>
<template v-slot:header>
<SpLogo />
</template>
<template v-slot:default>
<SpLinkIcon link="/" text="Dashboard" icon="Dashboard" />
<SpLinkIcon link="/modules" text="Modules" icon="Modules" />
<SpLinkIcon
link="/transactions"
text="Transactions"
icon="Transactions"
/>
<SpLinkIcon link="/types" text="Custom Type" icon="Form" />
<div class="sp-dash"></div>
<SpLinkIcon link="/settings" text="Settings" icon="Settings" />
<SpLinkIcon link="/docs" text="Documentation" icon="Docs" />
</template>
<template v-slot:footer>
<SpStatusAPI :showText="sidebarOpen" />
<SpStatusRPC :showText="sidebarOpen" />
<SpStatusWS :showText="sidebarOpen" />
<div class="sp-text">Build: v0.3.8</div>
</template>
</SpSidebar>
<Sidebar />
</template>
<template v-slot:content>
<router-view />
Expand All @@ -47,21 +21,24 @@ body {
<script>
import './scss/app.scss'
import '@starport/vue/lib/starport-vue.css'
import Sidebar from './components/Sidebar'

export default {
components: {
Sidebar
},
data() {
return {
initialized: false,
sidebarOpen: true
initialized: false
}
},
computed: {
hasWallet() {
return this.$store.hasModule(['chain', 'common', 'wallet'])
return this.$store.hasModule([ 'common', 'wallet'])
}
},
async created() {
await this.$store.dispatch('chain/common/env/init')
await this.$store.dispatch('common/env/init')
this.initialized = true
},
errorCaptured(err) {
Expand Down
35 changes: 35 additions & 0 deletions starport/templates/app/stargate/vue/src/components/Sidebar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template>
<SpSidebar
v-on:sidebar-open="sidebarOpen = true"
v-on:sidebar-close="sidebarOpen = false"
>
<template v-slot:default>
<SpLinkIcon link="/" text="Dashboard" icon="Dashboard" />
<SpLinkIcon link="/types" text="Custom Type" icon="Form" />
<div class="sp-dash"></div>
<SpLinkIcon href="https://github.com/tendermint/starport" target="_blank" text="Documentation" icon="Docs" />
</template>
<template v-slot:footer>
<SpStatusAPI :showText="sidebarOpen" />
<SpStatusRPC :showText="sidebarOpen" />
<SpStatusWS :showText="sidebarOpen" />
<div class="sp-text">Build: v0.3.8</div>
</template>
</SpSidebar>
</template>

<script>
export default {
name: 'Sidebar',
data() {
return {
sidebarOpen: true
}
},
computed: {
hasWallet() {
return this.$store.hasModule([ 'common', 'wallet'])
}
},
}
</script>
14 changes: 2 additions & 12 deletions starport/templates/app/stargate/vue/src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { createRouter, createWebHistory } from 'vue-router'
import Index from '@/views/Index.vue'
import Address from '@/views/Address.vue'
import Block from '@/views/Block.vue'
import Blocks from '@/views/Blocks.vue'
import Send from '@/views/Send.vue'
import Wallet from '@/views/Wallet.vue'
import Legacy from '@/views/Legacy.vue'
import Types from '@/views/Types.vue'

const routerHistory = createWebHistory()
const routes = [
{
path: '/',
component: Index
},
{ path: '/address/:address', component: Address },
{ path: '/block/:block', component: Block },
{ path: '/blocks/:page?', component: Blocks },
{ path: '/send/', component: Send },
{ path: '/wallet/', component: Wallet },
{ path: '/legacy/', component: Legacy }
{ path: '/types', component: Types }
]

const router = createRouter({
Expand Down
Loading
0