Skip to content

Commit

Permalink
Merge pull request #2706 from Emurgo/ruslan/cip30-experimental
Browse files Browse the repository at this point in the history
Updating to CIP-30 experimental API convention
  • Loading branch information
vsubhuman authored Feb 8, 2022
2 parents f42317b + c84f192 commit b78df3a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
8 changes: 4 additions & 4 deletions packages/yoroi-ergo-connector/example-cardano/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ function onApiConnectied(api) {
toggleSpinner('hide');
let walletDisplay = 'an anonymous Yoroi Wallet';

api.setReturnType(returnType);
api.experimental.setReturnType(returnType);

const auth = api.auth && api.auth();
const auth = api.experimental.auth && api.experimental.auth();
const authEnabled = auth && auth.isEnabled();

if (authEnabled) {
Expand All @@ -82,7 +82,7 @@ function onApiConnectied(api) {
accessGranted = true;
window.cardanoApi = cardanoApi = api;

api.onDisconnect(() => {
api.experimental.onDisconnect(() => {
alertWarrning(`Disconnected from ${walletDisplay}`);
toggleConnectionUI('button');
walletPlateSpan.innerHTML = '';
Expand Down Expand Up @@ -460,7 +460,7 @@ createTx.addEventListener('click', () => {
]
}

cardanoApi.createTx(txReq, true).then(txHex => {
cardanoApi.experimental.createTx(txReq, true).then(txHex => {
toggleSpinner('hide')
alertSuccess('Creating tx succeeds: ' + txHex)
transactionHex = txHex
Expand Down
46 changes: 25 additions & 21 deletions packages/yoroi-ergo-connector/src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,37 @@ class CardanoAPI {
});
}
setReturnType(returnType) {
if (returnType !== 'cbor' && returnType !== 'json') {
throw new Error('Possible return type values are: "cbor" or "json"');
}
this._returnType[0] = returnType;
}
experimental = Object.freeze({
setReturnType: (returnType) => {
if (returnType !== 'cbor' && returnType !== 'json') {
throw new Error('Possible return type values are: "cbor" or "json"');
}
this._returnType[0] = returnType;
},
auth: () => {
return this._auth;
},
createTx: (req) => {
return this._cardano_rpc_call("create_tx/cardano", [req]);
},
onDisconnect: (callback) => {
if (this._disconnection[0]) {
throw new Error('Cardano API instance is already disconnected!');
}
this._disconnection.push(callback);
},
})
getNetworkId() {
// TODO
throw new Error('Not implemented yet');
}
auth() {
return this._auth;
}
getBalance(token_id = '*') {
return this._cardano_rpc_call("get_balance", [token_id]);
}
Expand Down Expand Up @@ -226,17 +241,6 @@ class CardanoAPI {
// TODO
throw new Error('Not implemented yet');
}
createTx(req) {
return this._cardano_rpc_call("create_tx/cardano", [req]);
}
onDisconnect(callback) {
if (this._disconnection[0]) {
throw new Error('Cardano API instance is already disconnected!');
}
this._disconnection.push(callback);
}
}
`

Expand Down

0 comments on commit b78df3a

Please sign in to comment.