Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable auto suggestion for transfer input based off of users own transfer history #1964

Merged
merged 1 commit into from
Dec 19, 2017
Merged

Enable auto suggestion for transfer input based off of users own transfer history #1964

merged 1 commit into from
Dec 19, 2017

Conversation

netuoso
Copy link
Contributor

@netuoso netuoso commented Nov 11, 2017

Issue

Due to the inability to turn on basic autocomplete in the transfer form, users were encountering issues and scams by sending transfers to users with the wrong name. This is largely due to the fact that users had to constantly retype the name of the users they were sending transfers to.

Solution

As a solution to this issue, I have enabled the ability for condenser to check the users transfer history and suggest accounts based off this information.

Additional Config Options

This implementation of the autosuggest transfer feature activates only when the first letter of the name is typed and matched with available results. On top of this, the results are limited to 10 matches at a time in an effort to reduce screen disruption.

Screenshots

screen shot 2017-11-10 at 9 27 23 pm

screen shot 2017-11-10 at 9 33 49 pm

Copy link
Contributor

@bnchdrff bnchdrff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great overall. I'd rather avoid adding the uniq dependency and instead building the list of usernames like this:

currentAccount.get('transfer_history').reduce((acc, cur) => ({...acc, cur: true}), {})

and then just Object.keys() it.

this way we don't add more library weight.

@netuoso
Copy link
Contributor Author

netuoso commented Nov 13, 2017

I agree. I will make the suggested change.

@netuoso
Copy link
Contributor Author

netuoso commented Nov 14, 2017

Ok I was able to remove the need for uniq by using .filter(function(e,i,arr) {return arr.lastIndexOf(e) === i});

Wasn't able to get reduce to work the way I wanted. Maybe you can modify the filter to use reduce if you prefer. However this does result in the expected result of a sanitized array.

@TimCliff
Copy link
Contributor

TimCliff commented Nov 14, 2017

One use case I can think of where this would cause a problem is if a user had already transferred to a bad/wrong account, it would keep showing up in their list going forward. Could it at least check the list against the blacklisted accounts? Hopefully that will cover the worst scenarios.

@bnchdrff
Copy link
Contributor

what if we weighted a user's followed accounts to the top of the autocomplete list & denoted them as such?

@TimCliff
Copy link
Contributor

That would be good to do too.

@bnchdrff bnchdrff self-assigned this Nov 14, 2017
@netuoso
Copy link
Contributor Author

netuoso commented Nov 16, 2017

Great suggestions. Thanks for actually taking this one into consideration. I have been getting an immense benefit from the alpha version.

@bnchdrff
Copy link
Contributor

bnchdrff commented Nov 16, 2017

alright i've got this nice & cleaned up; switched to a more accessible autocomplete component, autocomplete includes followed users as well as previous transfers along with the # of times you transferred to them

todo:

  • on change, query steemd & see if the user has a negative rep and if so, display a warning
  • make sure it works with many many autocomplete & truncate if necessary
  • get ux / style feedback from @pkattera
  • generalize the autocomplete into a wrapper component maybe

@bnchdrff
Copy link
Contributor

to be clear, i think the only two immediate & critical issues are truncating the list & style feedback; the other two things can happen in later PRs

const transferToLog = currentAccount.get('transfer_history').reduce((acc, cur) => {
if (cur.getIn([1, 'op', 0]) === 'transfer') {
const username = cur.getIn([1, 'op', 1, 'to']);
const numTransfers = acc.get(username) ? acc.get(username).numTransfers + 1 : 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semi pls

@bnchdrff
Copy link
Contributor

bnchdrff commented Dec 8, 2017

i've rebased this PR; i'm happy with where it's at. @relativityboy take a peek.

@bnchdrff bnchdrff assigned relativityboy and unassigned bnchdrff Dec 8, 2017
Copy link
Contributor

@relativityboy relativityboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this PR's functionality in line with the above.

Also, with the latest rebase to master we're getting some errors in Autocomplete. That should be dealt with as well.

screen shot 2017-12-13 at 7 34 45 pm

.toMap()
.map(username => ({ username, label: labelFollowingUser }))
.merge(transferToLog)
.sortBy(u => u.numTransfers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bnchdrff @netuoso - this sort doesn't work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you saying we shouldn't sort by the number of previous transfers, or that it actually doesn't work? it's working for me:

screenshot from 2017-12-17 13-37-36

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah found a condition where it doesn't work, fixing it now...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't sort at all on live data. .sortBy return(s/ed) a list that has the same order as this.props.following.

There were 2 transfers in the list generated by .merge(transferToLog) with the rest being undefined. Neither of those had their order changed. The comparator fn will prob need to move to an a > b? 1 : (a < b? : -1 : 0) operation.

.merge(transferToLog)
.sortBy(u => u.numTransfers)
.reverse()
.toArray();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add a limit to 10 users (as suggested by @bnchdrff )

@bnchdrff
Copy link
Contributor

bnchdrff commented Dec 17, 2017

ok, made some changes: limited to 20 followed users & 20 transfer history users, and refactored to a method that only runs once (no need for a wrapper quite yet, we can do that if this has to be reused somewhere else)

@bnchdrff
Copy link
Contributor

i'm not sure how to do the negative rep thing quickly/easily ... i'd rather put that part into another PR since it's another boatload of work.

the getComputedStyle error is tricky; it's in react-autocomplete and i'm investigating it now.

@bnchdrff
Copy link
Contributor

the getComputedStyle is actually caused by our webpack config; we are overwriting global in dev.config.js https://github.com/steemit/condenser/blob/master/webpack/dev.config.js#L29 & prod.config.js https://github.com/steemit/condenser/blob/master/webpack/prod.config.js#L14

these were both defined in Initial commit 😠 06c90aa#diff-bb7d85ed7641f411d08dfc8a989a1dabR40 06c90aa#diff-5f694022cd10cae14c85a89025b45c45R64

things seem to run fine if i remove them, and there are no refs to this variable in our sourcetree; @valzav @roadscape @relativityboy any idea what the purpose of global.TYPED_ARRAY_SUPPORT might be?

@relativityboy
Copy link
Contributor

No idea

@bnchdrff
Copy link
Contributor

just checked if TYPED_ARRAY_SUPPORT is used anywhere else in the code back at Initial commit -- it's not!

@bnchdrff
Copy link
Contributor

bc@zebrina:~/steemit/condenser$ git log -GTYPED_ARRAY_SUPPORT 
commit 01669549774bba961a72d4d64ae8a2332c034f6c
Author: Valentine Zavgorodnev <[email protected]>
Date:   Thu Oct 12 16:46:41 2017 -0400

    Upgrade to webpack3 (#1797)
    
    * only webpack related changes from webpack3 branch
    
    * update steem-js in order to use http json rpc
    
    * move imports to the top (eliminate codeclimate warning)
    
    * bump npm version to 5.4.2

commit 06c90aa8260f09c4ae061e652d884f68b8a6a409
Author: James Calfee <[email protected]>
Date:   Thu Jul 28 09:58:41 2016 -0400

    Initial commit

@roadscape
Copy link
Contributor

Grepping node_modules, it seems this flag is used by buffer. @valzav added these flags originally, let's check with him.

@relativityboy
Copy link
Contributor

relativityboy commented Dec 18, 2017

This sorting on numTransfers now. That's really good. But the slice is happening too soon. This could result in significantly sub-optimal results for users with lots of transfers & followings.

User with just a few followings.
screen shot 2017-12-18 at 10 16 41 am

Same user with 20+ followings.
screen shot 2017-12-18 at 12 02 18 pm

@relativityboy
Copy link
Contributor

relativityboy commented Dec 18, 2017

I've updated the sortBy call to order by numTransfers desc, then username asc, and removed the trucate/slice because the single render means a user won't be prompted for their end-of-alphabet followings. @bnchdrff requesting 👍 / 👎 feedback

Same user, same dataset.
screen shot 2017-12-18 at 12 04 40 pm

@bnchdrff
Copy link
Contributor

@relativityboy looks fine to me; you aren't using that const yet though!

@bnchdrff
Copy link
Contributor

if you want to use a const for that one truncation, also pls use it for the other one as well

@roadscape
Copy link
Contributor

Implementation looks good to me, this will be a useful feature. Reliance on transfers list is fine for now, we can leverage better APIs in the future to populate the autocomplete.

Before merging we need clarification from @valzav why TYPED_ARRAY_SUPPORT was added; it's referenced by buffer which touches potentially critical functions such as signing.

@valzav
Copy link
Contributor

valzav commented Dec 18, 2017

@roadscape, I think you are right - TYPED_ARRAY_SUPPORT was needed for the buffer lib, it must be James who added it (I most probably just helped him with webpack's config). Not sure if it's steel needed. I would suggest to try to remove and check if it breaks anything.

@roadscape
Copy link
Contributor

Thanks Val, James' commits around that one have to do with adding a QR reader which has since been disabled. I also found a reference to this flag being related to browser compatibility issues with typed arrays (iOS/Safari in that case).

Browser support for typed arrays looks better currently: https://caniuse.com/#feat=typedarrays

In condenser, buffer seems to be mainly involved in these operations:

  • login
  • posting
  • image upload

@bnchdrff
Copy link
Contributor

i'm testing those ops now, and also looking through the code for other Buffer usage

@bnchdrff
Copy link
Contributor

tested login, image upload, posting, and account creation -- no errors found!

remove unused global override

see discussion at #1964 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants