-
Notifications
You must be signed in to change notification settings - Fork 20
feat(tangle-cloud): blueprint deployment request args configuration & finalization #2957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
91669f1
69d5320
5024c41
1565e6c
103c5dd
2d7eb11
1a89c84
994f69f
9f6fc95
91b1366
542354e
ca5f1d8
b7b936a
b702c82
05c9a58
5e00f67
ce63daa
35d9dd7
2219d1f
6c219bc
8948e8a
c1bb01b
4993916
8dab91a
608219f
539886d
3811490
5f6e410
b139beb
e74a3fe
ad6985f
3996aa7
240fea7
c952e4a
9fe12cb
71dbec5
c38bae2
58eb52c
67d42c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import optimizeTxBatch from '@tangle-network/tangle-shared-ui/utils/optimizeTxBatch'; | ||
import { SUCCESS_MESSAGES } from '../../hooks/useTxNotification'; | ||
import { useCallback } from 'react'; | ||
|
||
import { TxName } from '../../constants'; | ||
import { | ||
SubstrateTxFactory, | ||
useSubstrateTxWithNotification, | ||
} from '@tangle-network/tangle-shared-ui/hooks/useSubstrateTx'; | ||
import { RegisterServiceFormFields } from '../../types'; | ||
import { TANGLE_TOKEN_DECIMALS } from '@tangle-network/dapp-config'; | ||
import { parseUnits } from 'viem'; | ||
|
||
type Context = RegisterServiceFormFields; | ||
|
||
const useServicesRegisterTx = () => { | ||
const substrateTxFactory: SubstrateTxFactory<Context> = useCallback( | ||
async (api, _activeSubstrateAddress, context) => { | ||
const { blueprintIds, preferences, registrationArgs, amounts } = context; | ||
|
||
// TODO: Find a better way to get the chain decimals | ||
const decimals = | ||
api.registry.chainDecimals.length > 0 | ||
? api.registry.chainDecimals[0] | ||
: TANGLE_TOKEN_DECIMALS; | ||
Comment on lines
+16
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can import the network and get the decimals from it: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but it results in a recursive hook within a hook. @AtelyPham do you have any idea? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @danielbui12 using custom hooks within custom hooks is totally normal & common practice, if that's what you meant. Think about it like functions within functions -- it makes sense, it's simply building blocks reusing each other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any update here? @danielbui12 |
||
|
||
const registerTx = blueprintIds.map((blueprintId, idx) => { | ||
return api.tx.services.register( | ||
blueprintId, | ||
preferences[idx], | ||
registrationArgs[idx], | ||
parseUnits(amounts[idx].toString(), decimals), | ||
yuri-xyz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
}); | ||
|
||
return optimizeTxBatch(api, registerTx); | ||
}, | ||
[], | ||
); | ||
|
||
return useSubstrateTxWithNotification( | ||
TxName.REGISTER_BLUEPRINT, | ||
substrateTxFactory, | ||
SUCCESS_MESSAGES, | ||
); | ||
}; | ||
|
||
export default useServicesRegisterTx; |
Uh oh!
There was an error while loading. Please reload this page.