Bitcoin with Sats on Ecency Soon?

in ecency •  4 months ago

    After some thought I implemented this for proof of brain and it is live right now. Go and take a look. You have to change your settings.

    1. Login.
    2. Click on your wallet
    3. Click the 'Settings' tab
    4. Change the Currency setting to BTC

    Damn it looks cool. @ecency mentioned it might be a good idea to use 'satoshis.' He sounds interested. Which means it may end up being part of the main ecency code.

    I did some tweaking and recoding. The new implementation will use sats for a value that is less than a micro-bitcoin. It will use micro-bitcoins if it is less than a milli-bitcoin. Otherwise it will use millibitcoins for really high earners.

    --- a/src/common/components/formatted-currency/index.tsx
    +++ b/src/common/components/formatted-currency/index.tsx
    @@ -10,6 +10,8 @@ interface Props {
       fixAt: number;
     }
     
    +const prefixes = ["", "m", "µ", "n"];
    +
     export default class FormattedCurrency extends Component<Props> {
       public static defaultProps: Partial<Props> = {
         fixAt: 2
    @@ -21,6 +23,34 @@ export default class FormattedCurrency extends Component<Props> {
     
         const valInCurrency = value * currencyRate;
     
    -    return <>{formattedNumber(valInCurrency, { fractionDigits: fixAt, prefix: currencySymbol })}</>;
    +    let multiplier = 1.0;
    +    let prefix = '';
    +    if ( currencySymbol === '฿' && valInCurrency > 0) {
    +      let decimal_places = 0;
    +      let currency_string: string;
    +      for (; decimal_places < 9; decimal_places += 3, multiplier *= 1000) {
    +        const truncated_amount = Math.trunc( valInCurrency * Math.pow( 10, decimal_places + fixAt ) );
    +        if (isNaN(truncated_amount) || truncated_amount > 100) 
    +          break;
    +      }
    +      if (decimal_places === 9) {
    +        if (isNaN(multiplier*valInCurrency) || multiplier*valInCurrency === 0) {
    +          decimal_places = 0;
    +          multiplier = 1.0;          
    +        } else {
    +          return formattedNumber(valInCurrency * Math.pow(10,8),  { fractionDigits: 0, suffix: 'sats' } );
    +        }
    +      }
    +      prefix = prefixes[decimal_places / 3];
    +    }
    +
    +    return (
    +      <>
    +        {formattedNumber(valInCurrency * multiplier, {
    +          fractionDigits: fixAt,
    +          prefix: prefix + currencySymbol
    +        })}
    +      </>
    +    );
       }
     }
    

    Posted with proof of brain

      Authors get paid when people like you upvote their post.
      If you enjoyed what you read here, create your account today and start earning FREE VOILK!