Skip to content
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

Refactor/decorator2 #6693

Merged
merged 11 commits into from
Aug 16, 2023
49 changes: 20 additions & 29 deletions components/bsx/input/TokenBalanceInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,31 @@
expanded />
</template>

<script lang="ts">
<script setup lang="ts">
import BasicBalanceInput from '@/components/shared/form/BasicBalanceInput.vue'
import AssetMixin from '@/utils/mixins/assetMixin'
import { Component, Prop, VModel, mixins } from 'nuxt-property-decorator'

@Component({
components: {
BasicBalanceInput,
},
})
export default class TokenBalanceInput extends mixins(AssetMixin) {
@VModel() vValue!: string | number
@Prop({ type: String, required: false, default: '5' }) tokenId!:
| string
| number
// @Prop({ type: Number, default: '0' }) min!: number
// @Prop({ type: Number, default: undefined }) max!: number
const balanceInputComponent = ref<BasicBalanceInput>()

get asset() {
return this.assetIdOf(this.tokenId)
}
const emit = defineEmits(['input'])

get unit() {
return this.asset.symbol
}
const props = defineProps({
value: { type: String || Number, required: true },
tokenId: { type: String || Number, required: false, default: '5' },
})

get decimals() {
return this.asset.decimals
}
const vValue = computed({
get() {
return props.value
},
set(value) {
emit('input', value)
},
})
stephenjason89 marked this conversation as resolved.
Show resolved Hide resolved

public checkValidity() {
stephenjason89 marked this conversation as resolved.
Show resolved Hide resolved
const balanceInputComponent = this.$refs
.magicBalanceInput as BasicBalanceInput
return balanceInputComponent.checkValidity()
}
const asset = computed(() => useAsset().assetIdOf(props.tokenId))
stephenjason89 marked this conversation as resolved.
Show resolved Hide resolved
const unit = computed(() => asset.value.symbol)
const decimals = computed(() => asset.value.decimals)
function checkValidity() {
return balanceInputComponent.value?.checkValidity()
}
stephenjason89 marked this conversation as resolved.
Show resolved Hide resolved
</script>
64 changes: 29 additions & 35 deletions components/bsx/specific/MultiPaymentFeeButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,43 @@
</nuxt-link>
</template>

<script lang="ts">
<script setup lang="ts">
import { getAssetIdByAccount } from '@/utils/api/bsx/query'
import { Component, Prop, Watch, mixins } from 'nuxt-property-decorator'
import UseApiMixin from '@/utils/mixins/useApiMixin'
import AssetMixin from '@/utils/mixins/assetMixin'

import shouldUpdate from '@/utils/shouldUpdate'

@Component({})
export default class MultiPaymentFeeButton extends mixins(
AssetMixin,
UseApiMixin
) {
@Prop({ type: String, required: false }) public accountId!: string
@Prop({ type: String, default: 'bsx', required: false })
public prefix!: string
protected tokenId = '0'
const props = withDefaults(
defineProps<{
accountId: string
prefix?: string
}>(),
{ prefix: 'bsx' }
)
const tokenId = ref('0')
const asset = computed(() => useAsset().assetIdOf(tokenId.value))
stephenjason89 marked this conversation as resolved.
Show resolved Hide resolved

get asset() {
return this.assetIdOf(this.tokenId)
}
const unit = computed(() => asset.value.symbol)
const url = computed(() => `/${props.prefix}/assets`)

get unit() {
return this.asset.symbol
}

get url(): string {
return `/${this.prefix}/assets`
}

async fetchCurrency() {
try {
const api = await this.useApi()
this.tokenId = await getAssetIdByAccount(api, this.accountId)
} catch (e) {
this.$consola.log(e)
}
const fetchCurrency = async () => {
try {
const { apiInstance } = useApi()
const api = await apiInstance.value
tokenId.value = await getAssetIdByAccount(api, props.accountId)
} catch (e) {
console.log(e) // Use `console.log` instead of `this.$consola.log`
stephenjason89 marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Watch('accountId', { immediate: true })
onAccountIdChange(val: string, oldVal: string) {
watch(
() => props.accountId,
(val, oldVal) => {
if (shouldUpdate(val, oldVal)) {
this.fetchCurrency()
fetchCurrency()
}
},
{
immediate: true,
}
}
)
</script>
11 changes: 11 additions & 0 deletions composables/useAsset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useAssetsStore } from '~/stores/assets'

export default function () {
const assetIdOf = (id: string | number) => {
return useAssetsStore().getAssetById(String(id))
}

return {
assetIdOf,
}
}
stephenjason89 marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 0 additions & 16 deletions utils/mixins/assetMixin.ts

This file was deleted.