Skip to content

Commit

Permalink
update on tx submit callback
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitindenis1 committed Nov 14, 2023
1 parent fe50a08 commit 7dc290a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/dapp-example/src/QuickSwap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const TWAPComponent = ({ limit }: { limit?: boolean }) => {
getTokenLogoURL={getTokenLogoURL}
isDarkTheme={isDarkTheme}
limit={limit}
onTxSubmitted={() => console.log("submittted")}
onTxSubmitted={(args: any) => console.log(args)}
/>
);
};
Expand Down
21 changes: 8 additions & 13 deletions packages/lib/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,26 +147,21 @@ export const useCreateOrder = () => {
const wizardStore = useWizardStore();
const reset = useReset();
const { askDataParams, onTxSubmitted } = useTwapContext();
const dstUSD = useTwapStore((state) => state.getDstAmountUsdUi());
const setTokensFromDapp = useSetTokensFromDapp();
return useMutation(
async () => {
onTxSubmitted?.();
onTxSubmitted?.({
srcToken: store.srcToken!,
dstToken: store.dstToken!,
srcAmount: store.getSrcAmount().toString(),
dstUSD,
dstAmount: store.getDstAmount().toString(),
});
wizardStore.setAction(WizardAction.CREATE_ORDER);
wizardStore.setStatus(WizardActionStatus.PENDING);
const fillDelayMillis = (store.getFillDelayUiMillis() - store.lib!.estimatedDelayBetweenChunksMillis()) / 1000;

console.log({
srcToken: store.srcToken,
dstToken: store.dstToken,
srcAmount: store.getSrcAmount().toString(),
srcChunkAmount: store.getSrcChunkAmount().toString(),
dstMinChunkAmountOut: store.getDstMinAmountOut().toString(),
deadline: store.getDeadline(),
fillDelay: fillDelayMillis,
srcUsd: store.srcUsd.toString(),
priorityFeePerGas: priorityFeePerGas?.toString(),
maxFeePerGas: maxFeePerGas?.toString(),
});
analytics.onConfirmationCreateOrderClick();
store.setLoading(true);

Expand Down
11 changes: 10 additions & 1 deletion packages/lib/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export interface TWAPProps extends BaseProps {
onDstTokenSelected?: (token: any) => void;
TokenSelectModal: any;
limit?: boolean;
onTxSubmitted?: (values: OnTxSubmitValues) => void;
}

interface LibProps {
Expand Down Expand Up @@ -149,6 +150,14 @@ export interface TwapContextUIPreferences {
infoIcon?: IconType;
}

export type OnTxSubmitValues = {
srcToken: TokenData;
dstToken: TokenData;
srcAmount: string;
dstUSD: string;
dstAmount: string;
};

export interface TwapLibProps extends LibProps {
connect?: () => void;
askDataParams?: any[];
Expand All @@ -160,7 +169,7 @@ export interface TwapLibProps extends LibProps {
uiPreferences?: TwapContextUIPreferences;
onSrcTokenSelected?: (token: any) => void;
onDstTokenSelected?: (token: any) => void;
onTxSubmitted?: () => void;
onTxSubmitted?: (values: OnTxSubmitValues) => void;
}

export interface InitLibProps {
Expand Down
1 change: 0 additions & 1 deletion packages/quickswap/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ interface QuickSwapTWAPProps extends TWAPProps {
getTokenLogoURL: (address: string) => string;
dappTokens: { [key: string]: QuickSwapRawToken };
isProMode?: boolean;
onTxSubmitted?: () => void;
}

interface QuickSwapRawToken {
Expand Down

0 comments on commit 7dc290a

Please sign in to comment.