Moving Kin Between Apps: Technical Implementation Part I
Overview & Android
We recently published product and UX/I posts about our thoughts and related research on how to connect apps in the Kin Ecosystem. As previously mentioned, we would like people to be able to use Kin they earned in one app in any other ecosystem app. In these two posts, we went through a number of different options of achieving the required connection, including using a single wallet, merging wallets, and copying/pasting a public address, and discussed the reasons behind the solution we chose.
The first step to our solution that we recently released provides a discovery mechanism for ecosystem apps within Kinit. In this discovery list, users can find other apps that use Kin and install the ones they are interested in. The second step, which we are currently working on, will allow users to move Kin from Kinit to another ecosystem app without having to merge wallets or copy/paste a public address.
In this post I will dive into the technical details of how we decided to implement this, giving specific details on the Android implementation. We will follow soon with an additional post on the technical details of the iOS implementation.
Building a discovery solution was very straightforward. We simply added a new table to our back-end database containing the list of ecosystem apps and a REST API for our mobile apps to retrieve this list. The information in the table included the text and images needed for display and the link needed to open the app in Google Play or the App Store. We populated our table with the information provided by the application developers for each app, and released Android and iOS versions of Kinit that can display this. The table also includes a transfer_data column of type json, which contains specific details on how to conduct moving Kin to this app. If the transfer_data is null it means that the specific app does not yet support the ability to move Kin.
Android Implementation Details
The information pulled from our REST API is mapped into an EcosystemApp object in Kinit.
As you can see in the code above, the transferData is optional and comes from the transfer_data column on our server database. The field will be null if the specific app does not yet support moving Kin.
When a user of Kinit (and at a later stage, any other source app in the Kin Ecosystem) wants to move Kin from his account on Kinit to his account on another ecosystem app (we will call this the ‘destination app’), the Kinit application will need to know the public address of the user’s account on the destination app. To accomplish that, we used native (Android/iOS) abilities to interact between applications. Here is how it works:
- Kinit pulls a list of apps with their respective metadata for display and transferData for sending Kin from our Kinit server via a REST API.
- Kinit displays a list of the apps in the discovery screen. The user can click on one of the apps to view a details screen.
- In the discovery screens, Kinit displays either a ‘Get App’ button or ‘Send Kin’ button on each of the apps depending on whether the app supports moving Kin.
- Clicking on the ‘Get’ button takes the user to Google Play or the App Store
- Clicking on the ‘Send Kin’ button takes the user to a screen displaying a ‘Connecting apps’ animation screen and then opens the destination app, displaying a screen provided by the Ecosystem SDK that asks the user for approval.
- If the user approves, the ecosystem screen re-opens Kinit, providing the public address.
- Kinit prompts the user to enter the amount they want to transfer.
- Kinit uses the Kin SDKs to transfer Kin from the user’s account on Kinit to the public address of their account in the destination app.
- Once the transaction is completed, Kinit displays a completion success screen and sends our Kinit server the transaction details so that they can be added to the ‘Recent Actions’ tab in the ‘Balance’ screen.
Android Implementation Details
Kinit launches the destination app launch activity using the Android startActivityForResult method as follows:
The next version of the Ecosystem SDK will provide a default ‘moving kin’ launch activity for all apps that would like to include the ability to receive Kin from Kinit. We have been working closely with the ecosystem team to provide an implementation for this activity.
To protect the user’s privacy, the activity presents you with the option to approve or cancel. If the user cancels, the launch activity cancels:
If the user confirms, the launch activity generates a file containing the public address and sets the result to an intent containing the URI of a file provider, granting Kinit permissions to read.
We used a FileProvider in order to grant temporary permissions for Kinit to read the file while it is still inaccessible to other apps.
Once the result is set on the ecosystem activity, onActivityResult is called on the Kinit activity that initiated the request.
Once Kinit has the public address, it can easily move any amount of Kin that the user requests from the user’s Kinit account to the destination app account.
The code pieces here are modified to make it easier to understand the flow.
All of our code is open source, so if you’d like to see the full version you can find it here: Kinit Android, Kinit server, Ecosystem SDK Android