Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

Commit a3d26aa

Browse files
committed
DEV: Clean up helpers
* remove an unused helper * move a single-use helper to its call-site as a getter * convert `format-currency` to a pure function helper
1 parent 7107966 commit a3d26aa

5 files changed

Lines changed: 19 additions & 31 deletions

File tree

assets/javascripts/discourse/connectors/user-main-nav/billing.gjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import Component from "@ember/component";
22
import { LinkTo } from "@ember/routing";
3+
import { service } from "@ember/service";
34
import { classNames, tagName } from "@ember-decorators/component";
45
import icon from "discourse/helpers/d-icon";
56
import { i18n } from "discourse-i18n";
6-
import userViewingSelf from "../../helpers/user-viewing-self";
77

88
@tagName("li")
99
@classNames("user-main-nav-outlet", "billing")
1010
export default class Billing extends Component {
11+
@service currentUser;
12+
13+
get viewingSelf() {
14+
return (
15+
this.currentUser &&
16+
this.currentUser.username.toLowerCase() ===
17+
this.model.username.toLowerCase()
18+
);
19+
}
20+
1121
<template>
12-
{{#if (userViewingSelf this.model)}}
22+
{{#if this.viewingSelf}}
1323
<LinkTo @route="user.billing">
1424
{{icon "far-credit-card"}}
1525
{{i18n "discourse_subscriptions.navigation.billing"}}

assets/javascripts/discourse/helpers/format-currency.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { helper } from "@ember/component/helper";
2-
3-
export function formatCurrency([currency, amount]) {
1+
export default function formatCurrency(currency, amount) {
42
let currencySign;
53

64
switch (currency.toUpperCase()) {
@@ -38,8 +36,6 @@ export function formatCurrency([currency, amount]) {
3836
currencySign = "$";
3937
}
4038

41-
let formattedAmount = parseFloat(amount).toFixed(2);
39+
const formattedAmount = parseFloat(amount).toFixed(2);
4240
return currencySign + formattedAmount;
4341
}
44-
45-
export default helper(formatCurrency);

assets/javascripts/discourse/helpers/stripe-payment-link.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

assets/javascripts/discourse/helpers/user-viewing-self.js

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { setupTest } from "ember-qunit";
22
import { module, test } from "qunit";
3-
import { formatCurrency } from "discourse/plugins/discourse-subscriptions/discourse/helpers/format-currency";
3+
import formatCurrency from "discourse/plugins/discourse-subscriptions/discourse/helpers/format-currency";
44

55
module("Subscriptions | Unit | Helper | format-currency", function (hooks) {
66
setupTest(hooks);
77

8-
test("it formats USD correctly", function (assert) {
9-
let result = formatCurrency(["USD", 338.2]);
8+
test("formats USD correctly", function (assert) {
9+
const result = formatCurrency("USD", 338.2);
1010
assert.equal(result, "$338.20", "Formats USD correctly");
1111
});
1212

13-
test("it rounds correctly", function (assert) {
14-
let result = formatCurrency(["USD", 338.289]);
13+
test("rounds correctly", function (assert) {
14+
const result = formatCurrency("USD", 338.289);
1515
assert.equal(result, "$338.29", "Rounds correctly");
1616
});
1717
});

0 commit comments

Comments
 (0)