Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/yellow-schools-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@minima-global/mds": patch
---

added getStateVariable util function
17 changes: 16 additions & 1 deletion packages/mds/src/mds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { createCommandFunction } from './helpers.js';
import type { MDSObj } from './index.js';
import type { Coin, MDSObj } from './index.js';

var MDS_MAIN_CALLBACK: any;
var API_CALLS: any[] = [];
Expand Down Expand Up @@ -341,6 +341,21 @@ export const MDS: MDSObj = {
}
return bytes.buffer;
},

getStateVariable: (coin, port) => {
//Get the state vars
var statvars = coin.state;
if (Array.isArray(statvars)) {
var len = statvars.length;
for (var i = 0; i < len; i++) {
var state = statvars[i];
if (state?.port == port) {
return state.data;
}
}
}
return undefined;
},
},
};

Expand Down
7 changes: 7 additions & 0 deletions packages/mds/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,5 +378,12 @@ export interface MDSObj {
* @param hex The HEX string to convert
*/
base64ToArrayBuffer: (base64: string) => ArrayBuffer;

/**
* Get a state variable from a coin
* @param coin The coin to get the state variable from
* @param port The port to get the state variable from
*/
getStateVariable: (coin: Coin, port: number) => string | undefined;
};
}
14 changes: 3 additions & 11 deletions tests/test-app-new/src/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,9 @@ const AppProvider: React.FC<React.PropsWithChildren> = ({ children }) => {

const coins = await MDS.cmd.coins()

coins.response.forEach((coin) => {
if (coin.state) {
if (Array.isArray(coin.state)) {
coin.state.forEach((state) => {
console.log(state.data)
})
} else {
console.log(coin.state["0"])
}
}
})
console.log(coins.response[0])

console.log(MDS.util.getStateVariable(coins.response[0], 2))
}
})
}
Expand Down
Binary file modified tests/test-app-new/test-app-0.1.0.mds.zip
Binary file not shown.