Skip to content

Commit

Permalink
refactor token formatting using mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
beesaferoot committed Dec 11, 2024
1 parent e088d44 commit 8c8af96
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
11 changes: 11 additions & 0 deletions src/frontend/src/mixins/token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const token = {
methods: {
formatToken(token) {
// Ensure token is a string
const tokenStr = String(token)
// Format in the desired pattern
// return tokenStr.match(/.{1,4}/g).join('-'); // For "1234-1234-1234"
return tokenStr.match(/.{1,3}/g).join(" ") // For "123 412 341 234"
},
},
}
14 changes: 4 additions & 10 deletions src/frontend/src/modules/Meter/Transactions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
{{ token.paid_for_type }}
</md-table-cell>
<md-table-cell
v-if="token.paid_for_type === 'token'"
v-text="readable(token.paid_for.energy) + 'kWh'"
v-if="token.paid_for_type === 'App\\Models\\Token'"
v-text="readable(token.paid_for.energy) + ' kWh'"
></md-table-cell>
<md-table-cell v-else>-</md-table-cell>
<md-table-cell
Expand All @@ -49,10 +49,11 @@ import Widget from "../../shared/widget"
import { EventBus } from "@/shared/eventbus"
import { currency } from "@/mixins/currency"
import { timing } from "@/mixins/timing"
import { token } from "@/mixins/token"
export default {
name: "Transactions.vue",
mixins: [currency, timing],
mixins: [currency, timing, token],
components: { Widget },
props: {
transactions: {
Expand Down Expand Up @@ -92,13 +93,6 @@ export default {
this.transactions.tokens.length,
)
},
formatToken(token) {
// Ensure token is a string
const tokenStr = String(token)
// Format in the desired pattern
// return tokenStr.match(/.{1,4}/g).join('-'); // For "1234-1234-1234"
return tokenStr.match(/.{1,3}/g).join(" ") // For "123 412 341 234"
},
},
}
</script>
Expand Down

0 comments on commit 8c8af96

Please sign in to comment.