Profile

User Public & Private Profile

HandCash Connect provides default access to the user’s public profile. The user’s private profile can also be accessed, given that those permissions are granted.


The profile.getCurrentProfile function will return both objects if applicable, again depending on the permissions granted by the user.

const {HandCashConnect} = require('@handcash/handcash-connect');
const handCashConnect = new HandCashConnect('<app-id>'); 

const account = handCashConnect.getAccountFromAuthToken(token);

// Fetch and log the entire profile
const currentProfile = await account.profile.getCurrentProfile();
console.log(currentProfile);

// Extract public or private profile from currentProfile;
const {publicProfile, privateProfile} = currentProfile;
console.log(publicProfile);
console.log(privateProfile);

Output:

// Full profile
{
   publicProfile: {
      id: "5f15c31c3c177d003028eb97",
      handle: "stuk_91",
      paymail: "BrandonIAE@internal.handcash.io",
      displayName: "Steven Urban K.",
      avatarUrl: "https://handcash.io/avatar/7d399a0c-22cf-40cf-b162-f5511a4645db",
      localCurrencyCode: "USD",
   },
   privateProfile: { 
      phoneNumber: "+11234567891",
      email: "StevenUrban1234@gmail.com" 
   }
}
// Public profile 
{
   id: "5f15c31c3c177d003028eb97",
   handle: "stuk_91",
   paymail: "BrandonIAE@internal.handcash.io",
   displayName: "Steven Urban K.",
   avatarUrl: "https://handcash.io/avatar/7d399a0c-22cf-40cf-b162-f5511a4645db",
   localCurrencyCode: "USD",
},
// Private profile 
{ 
   phoneNumber: "+11234567891",
   email: "StevenUrban1234@gmail.com" 
}



Fetch Public Profiles of other users

Public user data can also be fetched using the function account.profile.getPublicProfilesByHandle().

const {HandCashConnect} = require('@handcash/handcash-connect');
const handCashConnect = new HandCashConnect('<app-id>'); 

const account = handCashConnect.getAccountFromAuthToken(token);

// Fetch and log user profiles by handle
const userProfiles = await account.profile.getPublicProfilesByHandle(['cryptokang', 'eyeone']);
console.log(currentProfile);

Output:

[
  {
      id: "5f15c31c3c177d003028eb97",
      handle: "cryptokang",
      paymail: "cryptokang@handcash.io",
      displayName: "Brandon",
      avatarUrl: "https://handcash.io/avatar/7d399a0c-22cf-40cf-b162-f5511a4645db",
      localCurrencyCode: "USD",
   },
  {
      id: "5f14c41c3c188d003027eb77",
      handle: "eyeone",
      paymail: "eyeone@handcash.io",
      displayName: "Ivan",
      avatarUrl: "https://handcash.io/avatar/7d399a0c-22cf-40cf-b162-f5511a4645db",
      localCurrencyCode: "USD",
   },
]



Spendable Balance

This feature requires the Pay permission.

You can fetch the user’s spendable balance with the getSpendableBalance function.

const {HandCashConnect} = require('@handcash/handcash-connect');
const handCashConnect = new HandCashConnect('<app-id>'); 

const account = handCashConnect.getAccountFromAuthToken(token);
var balance = await account.wallet.getSpendableBalance();

console.log(balance);

Output:

{
  spendableSatoshiBalance: 1260000,
  spendableFiatBalance: 2.96,
  currencyCode: 'CAD'
}

HandCash users have a global limit for how much they’re willing to spend on apps, ‘spendable balance’ is the amount left before reaching that limit:



connect-limit
The default limit is 10USD.

You can also customize the currency conversion options by passing the currency code through the function (if not provided, it will return the user’s prefered currency by default).

var balance = await account.wallet.getSpendableBalance("USD");

console.log(balance);

Output:

{
  spendableSatoshiBalance: 1260000,
  spendableFiatBalance: 2.03,
  currencyCode: 'USD'
}



Friends

This feature requires the Friends permission. Otherwise you will receive an error.

Return a list of friends, each including their own public profile.

const {HandCashConnect} = require('@handcash/handcash-connect');
const handCashConnect = new HandCashConnect('<app-id>'); 

const account = handCashConnect.getAccountFromAuthToken(token);
const friends = await account.profile.getFriends();

console.log(friends);

Output:

[
  {
    id: '5fa2d0ebab7c740c9e7b3ecb',
    handle: 'nosetwo',
    paymail: 'nosetwo@internal.handcash.io',
    displayName: 'Nose two',
    avatarUrl: 'https://res.cloudinary.com/hk7jbd3jh/image/upload/v1574787300/gntqxv6ed7sacwpfwumj.jpg',
    localCurrencyCode: 'EUR'
  },
  {
    id: '5f64dfbd7549610022d2861b',
    handle: 'rjseibane',
    paymail: 'rjseibane@internal.handcash.io',
    displayName: 'Rafa JS',
    avatarUrl: 'https://res.cloudinary.com/hk7jbd3jh/image/upload/v1584356800/hprcfwdasenpnrqei3uz.jpg',
    localCurrencyCode: 'USD'
  }
]