Skip to content

Commit

Permalink
Update RN bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
ok300 committed Sep 21, 2023
1 parent 7981df6 commit d8ccf23
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -947,39 +947,6 @@ fun asLnUrlPayRequestDataList(arr: ReadableArray): List<LnUrlPayRequestData> {
return list
}

fun asLnUrlWithdrawOkData(data: ReadableMap): LnUrlWithdrawOkData? {
if (!validateMandatoryFields(
data,
arrayOf(
"invoice",
),
)
) {
return null
}
val invoice = data.getMap("invoice")?.let { asLnInvoice(it) }!!
return LnUrlWithdrawOkData(
invoice,
)
}

fun readableMapOf(lnUrlWithdrawOkData: LnUrlWithdrawOkData): ReadableMap {
return readableMapOf(
"invoice" to readableMapOf(lnUrlWithdrawOkData.invoice),
)
}

fun asLnUrlWithdrawOkDataList(arr: ReadableArray): List<LnUrlWithdrawOkData> {
val list = ArrayList<LnUrlWithdrawOkData>()
for (value in arr.toArrayList()) {
when (value) {
is ReadableMap -> list.add(asLnUrlWithdrawOkData(value)!!)
else -> throw IllegalArgumentException("Unsupported type ${value::class.java.name}")
}
}
return list
}

fun asLnUrlWithdrawRequestData(data: ReadableMap): LnUrlWithdrawRequestData? {
if (!validateMandatoryFields(
data,
Expand Down Expand Up @@ -1029,6 +996,39 @@ fun asLnUrlWithdrawRequestDataList(arr: ReadableArray): List<LnUrlWithdrawReques
return list
}

fun asLnUrlWithdrawSuccessData(data: ReadableMap): LnUrlWithdrawSuccessData? {
if (!validateMandatoryFields(
data,
arrayOf(
"invoice",
),
)
) {
return null
}
val invoice = data.getMap("invoice")?.let { asLnInvoice(it) }!!
return LnUrlWithdrawSuccessData(
invoice,
)
}

fun readableMapOf(lnUrlWithdrawSuccessData: LnUrlWithdrawSuccessData): ReadableMap {
return readableMapOf(
"invoice" to readableMapOf(lnUrlWithdrawSuccessData.invoice),
)
}

fun asLnUrlWithdrawSuccessDataList(arr: ReadableArray): List<LnUrlWithdrawSuccessData> {
val list = ArrayList<LnUrlWithdrawSuccessData>()
for (value in arr.toArrayList()) {
when (value) {
is ReadableMap -> list.add(asLnUrlWithdrawSuccessData(value)!!)
else -> throw IllegalArgumentException("Unsupported type ${value::class.java.name}")
}
}
return list
}

fun asLocaleOverrides(data: ReadableMap): LocaleOverrides? {
if (!validateMandatoryFields(
data,
Expand Down Expand Up @@ -2657,28 +2657,28 @@ fun readableMapOf(lnUrlPayResult: LnUrlPayResult): ReadableMap? {
return map
}

fun asLnUrlWithdrawCallbackStatus(data: ReadableMap): LnUrlWithdrawCallbackStatus? {
fun asLnUrlWithdrawResult(data: ReadableMap): LnUrlWithdrawResult? {
val type = data.getString("type")

if (type == "ok") {
return LnUrlWithdrawCallbackStatus.Ok(data.getMap("data")?.let { asLnUrlWithdrawOkData(it) }!!)
return LnUrlWithdrawResult.Ok(data.getMap("data")?.let { asLnUrlWithdrawSuccessData(it) }!!)
}
if (type == "errorStatus") {
return LnUrlWithdrawCallbackStatus.ErrorStatus(data.getMap("data")?.let { asLnUrlErrorData(it) }!!)
return LnUrlWithdrawResult.ErrorStatus(data.getMap("data")?.let { asLnUrlErrorData(it) }!!)
}
return null
}

fun readableMapOf(lnUrlWithdrawCallbackStatus: LnUrlWithdrawCallbackStatus): ReadableMap? {
fun readableMapOf(lnUrlWithdrawResult: LnUrlWithdrawResult): ReadableMap? {
val map = Arguments.createMap()
when (lnUrlWithdrawCallbackStatus) {
is LnUrlWithdrawCallbackStatus.Ok -> {
when (lnUrlWithdrawResult) {
is LnUrlWithdrawResult.Ok -> {
pushToMap(map, "type", "ok")
pushToMap(map, "data", readableMapOf(lnUrlWithdrawCallbackStatus.data))
pushToMap(map, "data", readableMapOf(lnUrlWithdrawResult.data))
}
is LnUrlWithdrawCallbackStatus.ErrorStatus -> {
is LnUrlWithdrawResult.ErrorStatus -> {
pushToMap(map, "type", "errorStatus")
pushToMap(map, "data", readableMapOf(lnUrlWithdrawCallbackStatus.data))
pushToMap(map, "data", readableMapOf(lnUrlWithdrawResult.data))
}
}
return map
Expand Down
82 changes: 41 additions & 41 deletions libs/sdk-react-native/ios/BreezSDKMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -876,37 +876,6 @@ class BreezSDKMapper {
return lnUrlPayRequestDataList.map { v -> [String: Any?] in dictionaryOf(lnUrlPayRequestData: v) }
}

static func asLnUrlWithdrawOkData(data: [String: Any?]) throws -> LnUrlWithdrawOkData {
guard let invoiceTmp = data["invoice"] as? [String: Any?] else { throw SdkError.Generic(message: "Missing mandatory field invoice for type LnUrlWithdrawOkData") }
let invoice = try asLnInvoice(data: invoiceTmp)

return LnUrlWithdrawOkData(
invoice: invoice)
}

static func dictionaryOf(lnUrlWithdrawOkData: LnUrlWithdrawOkData) -> [String: Any?] {
return [
"invoice": dictionaryOf(lnInvoice: lnUrlWithdrawOkData.invoice),
]
}

static func asLnUrlWithdrawOkDataList(arr: [Any]) throws -> [LnUrlWithdrawOkData] {
var list = [LnUrlWithdrawOkData]()
for value in arr {
if let val = value as? [String: Any?] {
var lnUrlWithdrawOkData = try asLnUrlWithdrawOkData(data: val)
list.append(lnUrlWithdrawOkData)
} else {
throw SdkError.Generic(message: "Invalid element type LnUrlWithdrawOkData")
}
}
return list
}

static func arrayOf(lnUrlWithdrawOkDataList: [LnUrlWithdrawOkData]) -> [Any] {
return lnUrlWithdrawOkDataList.map { v -> [String: Any?] in dictionaryOf(lnUrlWithdrawOkData: v) }
}

static func asLnUrlWithdrawRequestData(data: [String: Any?]) throws -> LnUrlWithdrawRequestData {
guard let callback = data["callback"] as? String else { throw SdkError.Generic(message: "Missing mandatory field callback for type LnUrlWithdrawRequestData") }
guard let k1 = data["k1"] as? String else { throw SdkError.Generic(message: "Missing mandatory field k1 for type LnUrlWithdrawRequestData") }
Expand Down Expand Up @@ -950,6 +919,37 @@ class BreezSDKMapper {
return lnUrlWithdrawRequestDataList.map { v -> [String: Any?] in dictionaryOf(lnUrlWithdrawRequestData: v) }
}

static func asLnUrlWithdrawSuccessData(data: [String: Any?]) throws -> LnUrlWithdrawSuccessData {
guard let invoiceTmp = data["invoice"] as? [String: Any?] else { throw SdkError.Generic(message: "Missing mandatory field invoice for type LnUrlWithdrawSuccessData") }
let invoice = try asLnInvoice(data: invoiceTmp)

return LnUrlWithdrawSuccessData(
invoice: invoice)
}

static func dictionaryOf(lnUrlWithdrawSuccessData: LnUrlWithdrawSuccessData) -> [String: Any?] {
return [
"invoice": dictionaryOf(lnInvoice: lnUrlWithdrawSuccessData.invoice),
]
}

static func asLnUrlWithdrawSuccessDataList(arr: [Any]) throws -> [LnUrlWithdrawSuccessData] {
var list = [LnUrlWithdrawSuccessData]()
for value in arr {
if let val = value as? [String: Any?] {
var lnUrlWithdrawSuccessData = try asLnUrlWithdrawSuccessData(data: val)
list.append(lnUrlWithdrawSuccessData)
} else {
throw SdkError.Generic(message: "Invalid element type LnUrlWithdrawSuccessData")
}
}
return list
}

static func arrayOf(lnUrlWithdrawSuccessDataList: [LnUrlWithdrawSuccessData]) -> [Any] {
return lnUrlWithdrawSuccessDataList.map { v -> [String: Any?] in dictionaryOf(lnUrlWithdrawSuccessData: v) }
}

static func asLocaleOverrides(data: [String: Any?]) throws -> LocaleOverrides {
guard let locale = data["locale"] as? String else { throw SdkError.Generic(message: "Missing mandatory field locale for type LocaleOverrides") }
let spacing = data["spacing"] as? UInt32
Expand Down Expand Up @@ -2630,32 +2630,32 @@ class BreezSDKMapper {
}
}

static func asLnUrlWithdrawCallbackStatus(data: [String: Any?]) throws -> LnUrlWithdrawCallbackStatus {
static func asLnUrlWithdrawResult(data: [String: Any?]) throws -> LnUrlWithdrawResult {
let type = data["type"] as! String
if type == "ok" {
guard let dataTmp = data["data"] as? [String: Any?] else { throw SdkError.Generic(message: "Missing mandatory field data for type LnUrlWithdrawCallbackStatus") }
let _data = try asLnUrlWithdrawOkData(data: dataTmp)
guard let dataTmp = data["data"] as? [String: Any?] else { throw SdkError.Generic(message: "Missing mandatory field data for type LnUrlWithdrawResult") }
let _data = try asLnUrlWithdrawSuccessData(data: dataTmp)

return LnUrlWithdrawCallbackStatus.ok(data: _data)
return LnUrlWithdrawResult.ok(data: _data)
}
if type == "errorStatus" {
guard let dataTmp = data["data"] as? [String: Any?] else { throw SdkError.Generic(message: "Missing mandatory field data for type LnUrlWithdrawCallbackStatus") }
guard let dataTmp = data["data"] as? [String: Any?] else { throw SdkError.Generic(message: "Missing mandatory field data for type LnUrlWithdrawResult") }
let _data = try asLnUrlErrorData(data: dataTmp)

return LnUrlWithdrawCallbackStatus.errorStatus(data: _data)
return LnUrlWithdrawResult.errorStatus(data: _data)
}

throw SdkError.Generic(message: "Invalid enum variant \(type) for enum LnUrlWithdrawCallbackStatus")
throw SdkError.Generic(message: "Invalid enum variant \(type) for enum LnUrlWithdrawResult")
}

static func dictionaryOf(lnUrlWithdrawCallbackStatus: LnUrlWithdrawCallbackStatus) -> [String: Any?] {
switch lnUrlWithdrawCallbackStatus {
static func dictionaryOf(lnUrlWithdrawResult: LnUrlWithdrawResult) -> [String: Any?] {
switch lnUrlWithdrawResult {
case let .ok(
data
):
return [
"type": "ok",
"data": dictionaryOf(lnUrlWithdrawOkData: data),
"data": dictionaryOf(lnUrlWithdrawSuccessData: data),
]

case let .errorStatus(
Expand Down
2 changes: 1 addition & 1 deletion libs/sdk-react-native/ios/RNBreezSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class RNBreezSDK: RCTEventEmitter {
let lnUrlWithdrawRequestData = try BreezSDKMapper.asLnUrlWithdrawRequestData(data: reqData)
let descriptionTmp = description.isEmpty ? nil : description
var res = try getBreezServices().withdrawLnurl(reqData: lnUrlWithdrawRequestData, amountSats: amountSats, description: descriptionTmp)
resolve(BreezSDKMapper.dictionaryOf(lnUrlWithdrawCallbackStatus: res))
resolve(BreezSDKMapper.dictionaryOf(lnUrlWithdrawResult: res))
} catch let err {
rejectErr(err: err, reject: reject)
}
Expand Down
20 changes: 10 additions & 10 deletions libs/sdk-react-native/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ export type LnUrlPayRequestData = {
lnAddress?: string
}

export type LnUrlWithdrawOkData = {
invoice: LnInvoice
}

export type LnUrlWithdrawRequestData = {
callback: string
k1: string
Expand All @@ -176,6 +172,10 @@ export type LnUrlWithdrawRequestData = {
maxWithdrawable: number
}

export type LnUrlWithdrawSuccessData = {
invoice: LnInvoice
}

export type LocaleOverrides = {
locale: string
spacing?: number
Expand Down Expand Up @@ -518,16 +518,16 @@ export type LnUrlPayResult = {
data: LnUrlErrorData
}

export enum LnUrlWithdrawCallbackStatusVariant {
export enum LnUrlWithdrawResultVariant {
OK = "ok",
ERROR_STATUS = "errorStatus"
}

export type LnUrlWithdrawCallbackStatus = {
type: LnUrlWithdrawCallbackStatusVariant.OK,
data: LnUrlWithdrawOkData
export type LnUrlWithdrawResult = {
type: LnUrlWithdrawResultVariant.OK,
data: LnUrlWithdrawSuccessData
} | {
type: LnUrlWithdrawCallbackStatusVariant.ERROR_STATUS,
type: LnUrlWithdrawResultVariant.ERROR_STATUS,
data: LnUrlErrorData
}

Expand Down Expand Up @@ -677,7 +677,7 @@ export const payLnurl = async (reqData: LnUrlPayRequestData, amountSats: number,
return response
}

export const withdrawLnurl = async (reqData: LnUrlWithdrawRequestData, amountSats: number, description: string = ""): Promise<LnUrlWithdrawCallbackStatus> => {
export const withdrawLnurl = async (reqData: LnUrlWithdrawRequestData, amountSats: number, description: string = ""): Promise<LnUrlWithdrawResult> => {
const response = await BreezSDK.withdrawLnurl(reqData, amountSats, description)
return response
}
Expand Down

0 comments on commit d8ccf23

Please sign in to comment.