Griptape Update 2021-09-02
Agenda
- Current Development
- Next release
Current Development
WARNING
Note: any figures and code in this presentation are in development and therefore, not final.
Accesing Secret Network modules
Perform queries and transactions over Secret Network modules:
import {
useGovernance,
useStaking,
useTokenSwap
} from '@stakeordie/griptape.js';
...
1
2
3
4
5
6
2
3
4
5
6
Extending Contracts API: Error Handling
Do proper error handling to enhance UX:
import {
createContract,
onContractError,
OutOfGasError,
ServerUnavailableError
} from '@stakeordie/griptape.js';
const counter = createContract(...);
onContractError(counter, OutOfGasError, () => showInUI())
onContractError(counter, ServerUnavailableError, () => handleError())
try {
await counter.doTx();
} catch (e) {
// Any error not defined using `onContractError` will still be thrown.
} finally {
// Update UI or anything else
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Extending Contracts API: Contracts Registry
Adding a new API for getting contracts at runtime:
import {
snip20Def,
createContract,
getContract
} from '@stakeordie/griptape.js';
const stkd = createContract(...);
const list = getSnip20s(); // [ { symbol: '...', address: '...' } ]
list.forEach(({ symbol: id, address: at }) => {
const spec = { id, at, definition: snip20Def };
createContract(spec);
})
getContract('sefi').getBalance();
getContract('stkd').getBalance();
getContract('stkd') === stkd // true
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
What to start building? Lets add State Management.
Some examples about how to use vanilla griptape.js with state managers such a Vuex:
import { sust } from '@/contracts';
import { getError } from './errors';
export default {
namespaced: true,
state: {
// The balance for UST.
balance: undefined
},
// Hate Vuex.
mutations: {
updateBalance: (state, balance) => state.balance = balance,
},
actions: {
// Updates the UST balance.
async updateBalance({ commit }) {
const { balance: { amount } } = await sust.getBalance();
commit('updateBalance', amount);
},
// Perform a deposit to the UST contract.
async deposit({ dispatch }, amount) {
try {
await sust.deposit(amount);
dispatch('messages/message', {
type: 'success',
message: 'You have successfully deposited!'
},
{ root: true }
);
} catch (e) {
const { type, message } = getError(e);
dispatch('messages/message', { type, message }, { root: true });
} finally {
// Update the SUST balance.
dispatch('updateBalance')
// Update the UST Staking Pool balance.
dispatch('ustStakingPool/updateBalance', null, { root: true });
// Update total value locked.
dispatch('ustStakingPool/updateTotalLocked', null, { root: true });
}
}
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Next Release
griptape.js:0.5.X
- Accesing Secret Network modules
- Extending Contracts API: Error Handling
- Extending Contracts API: Contracts Registry