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
47 changes: 16 additions & 31 deletions components/bsx/input/TokenBalanceInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,25 @@
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

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: () => props.value,
set: (value) => {
emit('input', value)
},
})

public checkValidity() {
stephenjason89 marked this conversation as resolved.
Show resolved Hide resolved
const balanceInputComponent = this.$refs
.magicBalanceInput as BasicBalanceInput
return balanceInputComponent.checkValidity()
}
}
const { assets } = usePrefix()
const asset = computed(() => assets(props.tokenId))
const unit = computed(() => asset.value.symbol)
const decimals = computed(() => asset.value.decimals)
</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'
const { $consola } = useNuxtApp()

@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)
}

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

get url(): string {
return `/${this.prefix}/assets`
}
const unit = computed(() => asset.value.symbol)
const url = computed(() => `/${props.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) {
$consola.warn(e)
}
}

@Watch('accountId', { immediate: true })
onAccountIdChange(val: string, oldVal: string) {
watch(
() => props.accountId,
(val, oldVal) => {
if (shouldUpdate(val, oldVal)) {
this.fetchCurrency()
fetchCurrency()
}
},
{
immediate: true,
}
}
)
</script>
16 changes: 0 additions & 16 deletions utils/mixins/assetMixin.ts

This file was deleted.