Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

Commit

Permalink
fix(account-address): stop cutting out first character in the middle
Browse files Browse the repository at this point in the history
Fixes #8.
  • Loading branch information
devinus committed Mar 19, 2018
1 parent f384a2b commit f6881e8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
10 changes: 6 additions & 4 deletions app/components/account-address/component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Component from '@ember/component';
import { bool } from '@ember/object/computed';

import { observes } from 'ember-decorators/object';
import { on } from 'ember-decorators/object/evented';
Expand All @@ -7,11 +8,12 @@ export const MINIMUM_LENGTH = 64;

export default Component.extend({
tagName: 'span',
isVisible: bool('value'),

value: null,
truncate: false,
truncate: 0,

attributeBindings: ['value:title', 'translate'],
attributeBindings: ['title', 'translate'],
translate: false,

head: null,
Expand All @@ -25,8 +27,8 @@ export default Component.extend({
if (value) {
const str = String(value);
if (str.length >= MINIMUM_LENGTH) {
const head = str.slice(0, 10);
const body = str.slice(11, -5);
const head = str.slice(0, 9);
const body = str.slice(9, -5);
const tail = str.slice(-5);
this.setProperties({ head, body, tail });
}
Expand Down
4 changes: 1 addition & 3 deletions app/components/account-address/template.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{{#if value}}
<span>{{head}}</span><span class="middle">{{if truncate (truncate body truncate) body}}</span><span>{{tail}}</span>
{{/if}}
<span>{{head}}</span><span class="text-muted">{{if truncate (truncate body truncate) body}}</span><span>{{tail}}</span>
23 changes: 23 additions & 0 deletions tests/integration/components/account-address/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,27 @@ describe('Integration | Component | account-address', () => {
this.render(hbs`{{account-address}}`);
expect(this.$()).to.have.length(1);
});

it('displays the full address', function () {
const value = 'xrb_3arg3asgtigae3xckabaaewkx3bzsh7nwz7jkmjos79ihyaxwphhm6qgjps4';
this.set('value', value);
this.render(hbs`{{account-address value=value}}`);

const address = this.$().text().trim();
expect(address).to.equal(value);
});

it('visually separates the first 9 and last 5 characters', function () {
const value = 'xrb_3arg3asgtigae3xckabaaewkx3bzsh7nwz7jkmjos79ihyaxwphhm6qgjps4';
this.set('value', value);
this.render(hbs`{{account-address value=value}}`);

const parts = this.$('span > span');
expect(parts).to.have.length(3);

const [head, body, tail] = parts.map((idx, el) => el.innerText.trim());
expect(head).to.equal('xrb_3arg3');
expect(body).to.equal('asgtigae3xckabaaewkx3bzsh7nwz7jkmjos79ihyaxwphhm6q');
expect(tail).to.equal('gjps4');
});
});

0 comments on commit f6881e8

Please sign in to comment.