Skip to content

Commit

Permalink
feat(create-market): Add create market client call (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredvu authored Oct 15, 2024
1 parent b13c383 commit eb927e3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@cosmjs/tendermint-rpc": "^0.32.1",
"@datadog/browser-logs": "^5.23.3",
"@dydxprotocol/v4-abacus": "1.12.23",
"@dydxprotocol/v4-client-js": "1.10.0",
"@dydxprotocol/v4-client-js": "1.11.0",
"@dydxprotocol/v4-localization": "^1.1.217",
"@dydxprotocol/v4-proto": "^7.0.0-dev.0",
"@emotion/is-prop-valid": "^1.3.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/hooks/useSubaccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,22 @@ const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: LocalWall
[compositeClient, localDydxWallet, newMarketProposal]
);

// ------ Listing Method ------ //
const createPermissionlessMarket = useCallback(
async (ticker: string) => {
if (!compositeClient) {
throw new Error('client not initialized');
} else if (!subaccountClient?.address) {
throw new Error('wallet not initialized');
}

const response = await compositeClient.createMarketPermissionless(subaccountClient, ticker);

return response;
},
[compositeClient, subaccountClient]
);

// ------ Staking Methods ------ //
const delegate = useCallback(
async (validator: string, amount: number) => {
Expand Down Expand Up @@ -1051,6 +1067,9 @@ const useSubaccountContext = ({ localDydxWallet }: { localDydxWallet?: LocalWall
// Governance Methods
submitNewMarketProposal,

// Listing Methods
createPermissionlessMarket,

// Staking methods
delegate,
getDelegateFee,
Expand Down
7 changes: 6 additions & 1 deletion src/views/forms/NewMarketForm/v7/NewMarketPreviewStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { STRING_KEYS } from '@/constants/localization';

import { useMetadataServiceAssetFromId } from '@/hooks/useLaunchableMarkets';
import { useStringGetter } from '@/hooks/useStringGetter';
import { useSubaccount } from '@/hooks/useSubaccount';

import { formMixins } from '@/styles/formMixins';
import { layoutMixins } from '@/styles/layoutMixins';
Expand Down Expand Up @@ -46,6 +47,7 @@ export const NewMarketPreviewStep = ({
const [showAgreement, setShowAgreement] = useState(false);
const baseAsset = getDisplayableAssetFromTicker(ticker);
const launchableAsset = useMetadataServiceAssetFromId(ticker);
const { createPermissionlessMarket } = useSubaccount();

const alertMessage = useMemo(() => {
let alert;
Expand Down Expand Up @@ -161,9 +163,12 @@ export const NewMarketPreviewStep = ({
setErrorMessage(undefined);

try {
const response = await createPermissionlessMarket(ticker);
// eslint-disable-next-line no-console
console.log('debug:createPermissionlessMarket', response);
onSuccess(ticker);
} catch (error) {
log('NewMarketPreviewForm/submitNewMarketProposal', error);
log('NewMarketPreviewForm/createPermissionlessMarket', error);
setErrorMessage(error.message);
} finally {
setIsLoading(false);
Expand Down

0 comments on commit eb927e3

Please sign in to comment.