Skip to content

Commit

Permalink
added foreing metods to CIP30Wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis-omega committed Sep 25, 2022
1 parent 06e3bd6 commit e6ca384
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Wallet/Cip30.js
@@ -1,5 +1,13 @@
/* global BROWSER_RUNTIME */

exports._getNetworkId = conn => () => conn.getNetworkId();

exports._getUnusedAddresses = conn => () => conn._getUnusedAddresses();

exports._getChangeAddress = conn => () => conn._getChangeAddress();

exports._getRewardAddresses = conn => () => conn._getRewardAddresses();

exports._getAddresses = conn => conn.getUsedAddresses;

exports._getCollateral = maybe => conn => () =>
Expand Down
20 changes: 20 additions & 0 deletions src/Wallet/Cip30.purs
Expand Up @@ -40,6 +40,7 @@ type Cip30Wallet =
connection :: Cip30Connection
-- Get the address associated with the wallet (Nami does not support
-- multiple addresses)
, getNetworkId :: Cip30Connection -> Aff Int
, getWalletAddresses :: Cip30Connection -> Aff (Maybe (Array Address))

-- Get combination of all available UTxOs
Expand Down Expand Up @@ -82,6 +83,9 @@ txToHex =
<<< map (byteArrayToHex <<< Serialization.toBytes <<< asOneOf)
<<< Serialization.convertTransaction

getNetworkId :: Cip30Connection -> Aff Int
getNetworkId = toAffE <<< _getNetworkId

getWalletAddresses :: Cip30Connection -> Aff (Maybe (Array Address))
getWalletAddresses conn = Promise.toAffE (_getAddresses conn) <#>
(traverse ((addressFromBytes <<< rawBytesAsCborBytes) <=< hexToRawBytes))
Expand Down Expand Up @@ -143,6 +147,22 @@ fromHexString act = map hexToRawBytes <<< Promise.toAffE <<< act
-------------------------------------------------------------------------------
foreign import data Cip30Connection :: Type

foreign import _getNetworkId
:: Cip30Connection
-> Effect (Promise Int)

foreign import _getUnusedAddresses
:: Cip30Connection
-> Effect ( Promise ( Array String))

foreign import _getChangeAddress
:: Cip30Connection
-> Effect ( Promise String )

foreign import _getRewardAddresses
:: Cip30Connection
-> Effect ( Promise ( Array String))

foreign import _getAddresses
:: Cip30Connection
-> Effect
Expand Down

0 comments on commit e6ca384

Please sign in to comment.