Making user custom_field available to Composer connector?

I’m very close to finishing a new plugin that allows members to pay to pin their own topics.

Just one little thing is eluding me. I store the user’s balance in a user custom_field, updating the balance when a payment is made. When a user creates a pinned topic, the balance is reduced. All works fine.

What I’d like to do is to hide the “Pinned” checkbox on the Composer if the user’s balance is zero or insufficient.

However, I can’t find an easy way to access the user custom_field from within the composer connector .js.es6 file

Current code (not working):

import { showTxns } from 'discourse/plugins/stripe/discourse-plugin-stripe/lib/txns';
import { getOwner } from 'discourse-common/lib/get-owner';

export default {
    shouldRender(args, component) {
        // FIXME not working
        const balance = component.currentUser.custom_fields["stripe_txn_balance"];
        const fee = component.siteSettings.stripe_plugin_fee;
        return balance >= fee;
    }
};

Do I need to make a call to the “store” (i.e. the backend) to query the custom_field?

Would appreciate your help.

5 Likes

In your plugin, I would add the current balance in the user serializer. That way, you’ll be able to do component.currentUser.get('balance').

5 Likes

Thanks @zogstrip, I’ll give that a go. Sounds like an elegant solution.