Skip to content

samarthpohekar/yat-lib-android

 
 

Repository files navigation

Yat Partner Integration Android Framework

This framework is designed to make it easy for Yat partners to integrate the Yat purchase or connect flows into their apps.

This repository contains an example app module named yat-lib-example that illustrates the steps below. The YatAppConfig instance in the MainActivity of the sample app needs to be edited for the app to function correctly.

Note to Developer

https://jitpack.io/#yat-labs/yat-lib-android

Constant URL values below in the class YatLib need to be adjusted according to the service locations.

class YatLib {

    // ...

    companion object {

        internal const val signingAPIBaseURL = "https://partner-aurora.emojid.me"
        internal const val userActivationAPIBaseURL = "https://partner.scratch.emojid.me"
        internal const val yatAPIBaseURL = "https://api-dev.yat.rocks/"
        internal const val yatWebAppBaseURL = "https://dev.yat.rocks"
        internal const val yatTermsURL = "https://pre-waitlist.y.at/terms"

        // ...

    }

    // ...

}

Requirements

  • Android OS 7.0+

Installation

  1. Add the JitPack repository in your root build.gradle at the end of repositories:

    allprojects {
        repositories {
            // ...
            maven { url 'https://jitpack.io' }
        }
    }
  2. Add the dependency:

    dependencies {
        implementation 'com.github.yat-labs:yat-lib-android:0.1.2'
    }
    

Usage

  1. This library uses deep links to return from the Yat web application back to the partner application. URL scheme of the deep link is agreed upon in between the Yat development team and the integration partner. Currently used scheme is {partner_key}://y.at?{query_params}. Add deep link support to your activity using an intent filter.

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
    
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
    
        <!--
            this example illustrates support for a deep link in the format
            myapp://y.at?{query_params}
        -->
        <data
            android:host="y.at"
            android:scheme="myapp" />
    </intent-filter>
  2. Implement the Yat library delegate in your activity.

    class MainActivity :
        AppCompatActivity(),
        YatLib.Delegate {
    
        // ...
    
        override fun onYatIntegrationComplete(yat: String) {
            /*
            * Code to run when the integration has completed successfully.
            */
        }
    
        override fun onYatIntegrationFailed(failureType: YatLib.FailureType) {
            /*
            * Code to run when the integration has failed.
            */
        }
    
        // ...
    
    }
  3. Implement a function that initializes the library with the app-specific constants, user information and Yat records that should be linked to the Yat.

    class MainActivity :
        AppCompatActivity(),
        YatLib.Delegate {
    
        // ...
    
        private fun initializeYatLib() {
            // library configuration
            val config = YatAppConfig(
                name = "Super Cool Wallet",
                sourceName = "SCW",
                // used in partner-specific URLs
                pathKey = "scw",
                // app-specific public key
                pubKey = "{64 character hex public key}",
                // app-specific access code
                code = "66b6a5aa-11b4-12a9-1c1e-84765ef174ab",
                // app-specific authentication token
                authToken = "AppToken84765783"
            )
            // Yat records
            val yatRecords = listOf(
                YatRecord(
                    YatRecordType.ADA_ADDRESS,
                    "DdzFFzCqrhsgwQmeWNBTsG8VjYunBLK9GNR93GSLTGj1FeMm8kFoby2cTHxEHBEraHQXmgTtFGz7fThjDRNNvwzcaw6fQdkYySBneRas"
                ),
                YatRecord(
                    YatRecordType.DOT_ADDRESS,
                    "GC8fuEZG4E5epGf5KGXtcDfvrc6HXE7GJ5YnbiqSpqdQYLg"
                ),
                YatRecord(
                    YatRecordType.BTC_ADDRESS,
                    "1NDyJtNTjmwk5xPNhjgAMu4HDHigtobu1s"
                ),
                YatRecord(
                    YatRecordType.ETH_ADDRESS,
                    "108dEFa0272dC118EF03a7993e4fC7A8AcF3a3d1"
                ),
                YatRecord(
                    YatRecordType.XTR_ADDRESS,
                    "d2e4db6dac593a9af36987a35676838ede4f69684ba433baeed68bce048e111b"
                ),
                YatRecord(
                    YatRecordType.XMR_STANDARD_ADDRESS,
                    "4AdUndXHHZ6cfufTMvppY6JwXNouMBzSkbLYfpAV5Usx3skxNgYeYTRj5UzqtReoS44qo9mtmXCqY45DJ852K5Jv2684Rge"
                )
            )
            // initialize the library
            YatLib.initialize(
                config = config,
                /*
                * User information below is utilized to link the partner application user
                * to the Yat user.
                */
                userId = "partner_app_user_identifier",
                userPassword = "partner_app_user_password",
                /*
                * YatLib.ColorMode.LIGHT for light mode,
                * YatLib.ColorMode.DARK for dark mode,
                */
                colorMode = YatLib.ColorMode.LIGHT,
                /*
                * Delegate interface is described below.
                */
                delegate = this,
                yatRecords = yatRecords
            )
        }
    
        // ...
    
    }
  4. Add the code that handles deep links.

    class MainActivity :
        AppCompatActivity(),
        YatLib.Delegate {
    
        // ...
    
        override fun onNewIntent(intent: Intent) {
            super.onNewIntent(intent)
            intent.data?.let { deepLink ->
                YatLib.processDeepLink(deepLink)
            }
        }
    
        // ...
    
    }
  5. Start the library.

    class MainActivity :
            AppCompatActivity(),
            YatLib.Delegate {
    
        // ...
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            ui = ActivityMainBinding.inflate(layoutInflater)
            setContentView(ui.root)
            initializeYatLib()
            ui.getAYatButton.setOnClickListener {
                YatLib.start(this@MainActivity)
            }
        }
    
        // ...
    
    }

Looking up a Yat

Below is an example call to the YatLib.lookupYat function to query for the records linked to a Yat and print them.

private fun lookupYat(yat: String) {
    YatLib.lookupYat(
        yat,
        onSuccess = { processLookupResponse(it) },
        onError = { _, _ ->
            val errorMessage = resources.getString(R.string.error_yat_lookup)
            displayErrorDialog(errorMessage)
        }
    )
}

private fun processLookupResponse(lookupResponse: YatLookupResponse) {
    for (record in lookupResponse.yatRecords) {
        val shortAddress =
            record.data.substring(0, 4) +
                    "..." +
                    record.data.substring(record.data.length - 4, record.data.length)
        println("${record.type} : $shortAddress")
    }
    ui.yatRecordsTitleTextView.visibility = View.VISIBLE
    ui.yatRecordsTextView.text = records
}

About

Yat integration framework for Android.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 99.3%
  • Java 0.7%