WICG / webmonetization

Proposed Web Monetization standard
https://webmonetization.org
Other
457 stars 153 forks source link

Should we consolidate amount/assetCode/assetScale into a single field? #240

Closed marcoscaceres closed 2 years ago

marcoscaceres commented 2 years ago

Raised elsewhere, it may be worth looking at consolidating amount/assetCode/assetScale into a single member. E.g.,:

"USD0.001"

However, that has several draw backs:

sublimator commented 2 years ago

You could use : separated values perhaps, something like 2:USD:2 for 2 cents to pack it into one field ? Shrug. I'm not really a fan of a single field unless it is an object.

marcoscaceres commented 2 years ago

Yeah, agree… that’s also not great, as then you need to remember what each position means. I.e., is the scale at index 0 or 2?

I think it’s probably best to leave this as is. It’s good to capture this discussion though, in case it comes up again.

Closing.

sublimator commented 2 years ago

The asset amount and assetScale could be combined, but this has internationalization issues: decimal points, etc. are represented/formatted differently across different cultures, so it's probably safer to leave them separate and allow developers to combine them and present them based on the user/site's localization settings.

The payment request spec simply uses value/currency: https://www.w3.org/TR/payment-request/#dfn-valid-decimal-monetary-value

They used a decimal format that simply uses a period as a decimal point. This format should present no more challenge to localizing than having to do calculation with an amount integer and assetScale

While dictionary might not work as an event attribute (see #16), a custom interface would

        [SecureContext, Exposed=Window]
        interface MonetizationAmount {
          readonly attribute DOMString value;
          readonly attribute DOMString currency;
        };

        [SecureContext, Exposed=Window]
        interface MonetizationEvent : Event {
          constructor(DOMString type, MonetizationEventInit eventInitDict);
          readonly attribute MonetizationAmount amount;