[질문]
react-native 에서 klip-sdk 를 이용할 수 있을까요? (javascript는 지원한다고 돼 있습니다만…)
혹 가능하다면 간단한 예시 공유를 부탁드립니다.
감사합니다.
[답변]
안녕하세요.
react-native가 공식 지원 항목에는 없지만, 내부 데모앱 제작 시 동작에 문제 없음을 확인하였습니다. 사용법은 react와 차이가 없다고 보시면 되겠습니다.
추가로 답변을 드려보자면, react-native에서 사용할 시 클립으로 넘어가는 request부분은 브라우저랑 작동이 달라 커스텀하게 Linking등을 사용하셔야 하지만 나머지 부분들은 klip-sdk를 사용할 수 있습니다. 아래는 auth request를 보내는 예시입니다.
import { Linking } from "react-native";
import { prepare, request, getResult } from 'klip-sdk'
const bappName = 'my app'
const successLink = 'myApp://...'
const failLink = 'myApp://...'
let requestKey
const prepareAuthRequest = async () => {
const res = await prepare.auth({ bappName, successLink, failLink })
if (res.err) {
// 에러 처리
} else if (res.request_key) {
requestKey = res.request_key
}
}
const sendRequest = () => {
Linking.openURL(`https://klipwallet.com/?target=/a2a?request_key=${requestKey}`)
}
const getRequestResult = async () => {
const res = await getResult(requestKey)
// do something with res
}