From db75fcdd2b81bcf2fa295bc4ceb98d97e54e0822 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Thu, 2 Nov 2023 18:06:28 +0100 Subject: [PATCH 01/33] add new sdk types --- .../src/forms/variables/useExternalVariableForm.ts | 4 ++-- .../src/forms/variables/useQueryVariableForm.tsx | 4 ++-- .../src/forms/variables/useStaticVariableForm.tsx | 4 ++-- .../condition-builder/condition-node/StringExprNode.tsx | 4 ++-- .../condition-node/value-input/ValueInput.tsx | 2 +- .../src/pages/job-new/condition-form/ConditionForm.tsx | 8 ++++---- .../details-form/template-var-input/TemplateVarInput.tsx | 2 +- apps/warp-protocol/src/pages/job-new/useJobStorage.ts | 4 ++-- .../Condition/typed-expressions/ExpressionValue.tsx | 2 +- .../Condition/typed-expressions/StringExpression.tsx | 2 +- .../dialogs/expression/UpdateFnValue.tsx | 2 +- .../src/pages/job-page/panels/JobMessagePanel.tsx | 8 ++++---- .../warp-protocol/src/pages/variables/details/Details.tsx | 7 +++++++ .../variables/dialogs/static/StaticVariableDialog.tsx | 7 +++++++ .../src/pages/variables/update-fn/ConcreteNode.tsx | 4 ++-- .../src/pages/variables/update-fn/EmptyNode.tsx | 6 +++--- .../src/pages/variables/update-fn/UpdateFnDialog.tsx | 8 ++++---- .../src/pages/variables/update-fn/UpdateFnNode.tsx | 4 ++-- .../src/pages/variables/update-fn/UpdateFnValueInput.tsx | 4 ++-- apps/warp-protocol/src/tx/useCreateJobTx.ts | 5 +++-- apps/warp-protocol/src/types/job.ts | 4 +++- 21 files changed, 56 insertions(+), 39 deletions(-) diff --git a/apps/warp-protocol/src/forms/variables/useExternalVariableForm.ts b/apps/warp-protocol/src/forms/variables/useExternalVariableForm.ts index c2c416ee..ba9a0179 100644 --- a/apps/warp-protocol/src/forms/variables/useExternalVariableForm.ts +++ b/apps/warp-protocol/src/forms/variables/useExternalVariableForm.ts @@ -8,8 +8,8 @@ export interface ExternalVariableInput { body?: string | null; headers?: object | null; method?: warp_resolver.Method | null; - onSuccess?: warp_resolver.UpdateFnValue; - onError?: warp_resolver.UpdateFnValue; + onSuccess?: warp_resolver.FnValue; + onError?: warp_resolver.FnValue; selector: string; url: string; encode: boolean; diff --git a/apps/warp-protocol/src/forms/variables/useQueryVariableForm.tsx b/apps/warp-protocol/src/forms/variables/useQueryVariableForm.tsx index 1127780f..f43ac61f 100644 --- a/apps/warp-protocol/src/forms/variables/useQueryVariableForm.tsx +++ b/apps/warp-protocol/src/forms/variables/useQueryVariableForm.tsx @@ -7,8 +7,8 @@ export interface QueryVariableInput { queryJson: string; kind: warp_resolver.VariableKind; querySelector: string; - onSuccess?: warp_resolver.UpdateFnValue; - onError?: warp_resolver.UpdateFnValue; + onSuccess?: warp_resolver.FnValue; + onError?: warp_resolver.FnValue; encode: boolean; reinitialize: boolean; } diff --git a/apps/warp-protocol/src/forms/variables/useStaticVariableForm.tsx b/apps/warp-protocol/src/forms/variables/useStaticVariableForm.tsx index 2eb83b8e..17253c9c 100644 --- a/apps/warp-protocol/src/forms/variables/useStaticVariableForm.tsx +++ b/apps/warp-protocol/src/forms/variables/useStaticVariableForm.tsx @@ -6,8 +6,8 @@ export interface StaticVariableInput { name: string; kind: warp_resolver.VariableKind; value: string; - onSuccess?: warp_resolver.UpdateFnValue; - onError?: warp_resolver.UpdateFnValue; + onSuccess?: warp_resolver.FnValue; + onError?: warp_resolver.FnValue; encode: boolean; } diff --git a/apps/warp-protocol/src/pages/job-new/condition-builder/condition-node/StringExprNode.tsx b/apps/warp-protocol/src/pages/job-new/condition-builder/condition-node/StringExprNode.tsx index 76eafba0..b3399d63 100644 --- a/apps/warp-protocol/src/pages/job-new/condition-builder/condition-node/StringExprNode.tsx +++ b/apps/warp-protocol/src/pages/job-new/condition-builder/condition-node/StringExprNode.tsx @@ -7,8 +7,8 @@ import styles from './ConditionNode.module.sass'; import { OperatorInput } from './operator-input/OperatorInput'; import { ValueInput } from './value-input/ValueInput'; -type Expr = warp_resolver.GenExprFor_ValueFor_StringAnd_StringOp; -type Value = warp_resolver.ValueFor_String; +type Expr = warp_resolver.GenExprFor_StringValueFor_StringAnd_StringOp; +type Value = warp_resolver.StringValueFor_String; type StringExprNodeProps = UIElementProps & { expr: Expr; diff --git a/apps/warp-protocol/src/pages/job-new/condition-builder/condition-node/value-input/ValueInput.tsx b/apps/warp-protocol/src/pages/job-new/condition-builder/condition-node/value-input/ValueInput.tsx index 59ec765d..ab2818e1 100644 --- a/apps/warp-protocol/src/pages/job-new/condition-builder/condition-node/value-input/ValueInput.tsx +++ b/apps/warp-protocol/src/pages/job-new/condition-builder/condition-node/value-input/ValueInput.tsx @@ -20,7 +20,7 @@ import { useEnvValueDialog } from './EnvValueDialog'; type Value = | warp_resolver.NumValueFor_Decimal256And_NumExprOpAnd_DecimalFnOp - | warp_resolver.ValueFor_String + | warp_resolver.StringValueFor_String | warp_resolver.NumValueForInt128And_NumExprOpAnd_IntFnOp | warp_resolver.NumValueFor_Uint256And_NumExprOpAnd_IntFnOp; diff --git a/apps/warp-protocol/src/pages/job-new/condition-form/ConditionForm.tsx b/apps/warp-protocol/src/pages/job-new/condition-form/ConditionForm.tsx index 17856d7a..d77b4b02 100644 --- a/apps/warp-protocol/src/pages/job-new/condition-form/ConditionForm.tsx +++ b/apps/warp-protocol/src/pages/job-new/condition-form/ConditionForm.tsx @@ -154,7 +154,7 @@ const validValue = ( value: | warp_resolver.NumValueFor_Uint256And_NumExprOpAnd_IntFnOp | warp_resolver.NumValueFor_Decimal256And_NumExprOpAnd_DecimalFnOp - | warp_resolver.ValueFor_String + | warp_resolver.StringValueFor_String | warp_resolver.NumValueForInt128And_NumExprOpAnd_IntFnOp ) => { if (validSimple(value) || validRef(value) || validEnv(value)) { @@ -168,7 +168,7 @@ const validSimple = ( value: | warp_resolver.NumValueFor_Uint256And_NumExprOpAnd_IntFnOp | warp_resolver.NumValueFor_Decimal256And_NumExprOpAnd_DecimalFnOp - | warp_resolver.ValueFor_String + | warp_resolver.StringValueFor_String | warp_resolver.NumValueForInt128And_NumExprOpAnd_IntFnOp ) => { if ('simple' in value) { @@ -182,7 +182,7 @@ const validRef = ( value: | warp_resolver.NumValueFor_Uint256And_NumExprOpAnd_IntFnOp | warp_resolver.NumValueFor_Decimal256And_NumExprOpAnd_DecimalFnOp - | warp_resolver.ValueFor_String + | warp_resolver.StringValueFor_String | warp_resolver.NumValueForInt128And_NumExprOpAnd_IntFnOp ) => { if ('ref' in value) { @@ -196,7 +196,7 @@ const validEnv = ( value: | warp_resolver.NumValueFor_Uint256And_NumExprOpAnd_IntFnOp | warp_resolver.NumValueFor_Decimal256And_NumExprOpAnd_DecimalFnOp - | warp_resolver.ValueFor_String + | warp_resolver.StringValueFor_String | warp_resolver.NumValueForInt128And_NumExprOpAnd_IntFnOp ) => { if ('env' in value) { diff --git a/apps/warp-protocol/src/pages/job-new/details-form/template-var-input/TemplateVarInput.tsx b/apps/warp-protocol/src/pages/job-new/details-form/template-var-input/TemplateVarInput.tsx index 9e5710b6..636534bb 100644 --- a/apps/warp-protocol/src/pages/job-new/details-form/template-var-input/TemplateVarInput.tsx +++ b/apps/warp-protocol/src/pages/job-new/details-form/template-var-input/TemplateVarInput.tsx @@ -109,7 +109,7 @@ export const TemplateVarInput = (props: TemplateVarInputProps) => { { diff --git a/apps/warp-protocol/src/pages/job-new/useJobStorage.ts b/apps/warp-protocol/src/pages/job-new/useJobStorage.ts index 8fc6ac2a..a23299ec 100644 --- a/apps/warp-protocol/src/pages/job-new/useJobStorage.ts +++ b/apps/warp-protocol/src/pages/job-new/useJobStorage.ts @@ -32,12 +32,12 @@ export const useJobStorage = () => { reward: demicrofy(job.reward, nativeToken.decimals).toString(), name: job.info.name, description: job.info.description, - message: JSON.stringify(job.info.msgs, null, 2), + message: JSON.stringify(job.msgs, null, 2), recurring: job.info.recurring, }; setDetailsInput(details); - setCond(job.info.condition); + setCond(job.condition); setVariables(job.info.vars); }, [setDetailsInput, setCond, nativeToken.decimals, setVariables] diff --git a/apps/warp-protocol/src/pages/job-page/panels/Condition/typed-expressions/ExpressionValue.tsx b/apps/warp-protocol/src/pages/job-page/panels/Condition/typed-expressions/ExpressionValue.tsx index 99266b04..2f3241fb 100644 --- a/apps/warp-protocol/src/pages/job-page/panels/Condition/typed-expressions/ExpressionValue.tsx +++ b/apps/warp-protocol/src/pages/job-page/panels/Condition/typed-expressions/ExpressionValue.tsx @@ -4,7 +4,7 @@ import { warp_resolver } from '@terra-money/warp-sdk'; import { VariableValue } from './VariableValue'; type ExprValue = - | warp_resolver.ValueFor_String + | warp_resolver.StringValueFor_String | warp_resolver.NumValueFor_Uint256And_NumExprOpAnd_IntFnOp | warp_resolver.NumValueFor_Decimal256And_NumExprOpAnd_DecimalFnOp | warp_resolver.NumValueForInt128And_NumExprOpAnd_IntFnOp; diff --git a/apps/warp-protocol/src/pages/job-page/panels/Condition/typed-expressions/StringExpression.tsx b/apps/warp-protocol/src/pages/job-page/panels/Condition/typed-expressions/StringExpression.tsx index b7461eb4..cf74047e 100644 --- a/apps/warp-protocol/src/pages/job-page/panels/Condition/typed-expressions/StringExpression.tsx +++ b/apps/warp-protocol/src/pages/job-page/panels/Condition/typed-expressions/StringExpression.tsx @@ -5,7 +5,7 @@ import { Job } from 'types/job'; import { ExpressionValue } from './ExpressionValue'; export type StringExpressionProps = { - expression: warp_resolver.GenExprFor_ValueFor_StringAnd_StringOp; + expression: warp_resolver.GenExprFor_StringValueFor_StringAnd_StringOp; job: Job; } & UIElementProps; diff --git a/apps/warp-protocol/src/pages/job-page/panels/Condition/typed-expressions/dialogs/expression/UpdateFnValue.tsx b/apps/warp-protocol/src/pages/job-page/panels/Condition/typed-expressions/dialogs/expression/UpdateFnValue.tsx index 1ba17025..adcfab09 100644 --- a/apps/warp-protocol/src/pages/job-page/panels/Condition/typed-expressions/dialogs/expression/UpdateFnValue.tsx +++ b/apps/warp-protocol/src/pages/job-page/panels/Condition/typed-expressions/dialogs/expression/UpdateFnValue.tsx @@ -3,7 +3,7 @@ import { warp_resolver } from '@terra-money/warp-sdk'; import { ExpressionValue } from './ExpressionValue'; export type UpdateFnValueProps = { - value: warp_resolver.UpdateFnValue; + value: warp_resolver.FnValue; variables: warp_resolver.Variable[]; } & UIElementProps; diff --git a/apps/warp-protocol/src/pages/job-page/panels/JobMessagePanel.tsx b/apps/warp-protocol/src/pages/job-page/panels/JobMessagePanel.tsx index 708b9de3..7a0e68f6 100644 --- a/apps/warp-protocol/src/pages/job-page/panels/JobMessagePanel.tsx +++ b/apps/warp-protocol/src/pages/job-page/panels/JobMessagePanel.tsx @@ -21,18 +21,18 @@ export const JobMessagePanel = (props: JobMessagePanelProps) => { const { job, className } = props; const [selectedTabType, setSelectedTabType] = useState('encoded'); - const [msgs, setMsgs] = useState(job.info.msgs); + const [msgs, setMsgs] = useState(job.msgs); const copy = useCopy('message', JSON.stringify(msgs, null, 2)); useEffect(() => { if (selectedTabType === 'encoded') { - setMsgs(job.info.msgs); + setMsgs(job.msgs); } if (selectedTabType === 'decoded') { - setMsgs(decodeMsgs(job.info.msgs)); + setMsgs(decodeMsgs(job.msgs)); } - }, [job.info.msgs, selectedTabType]); + }, [job.msgs, selectedTabType]); return ( diff --git a/apps/warp-protocol/src/pages/variables/details/Details.tsx b/apps/warp-protocol/src/pages/variables/details/Details.tsx index c6736637..d38ed133 100644 --- a/apps/warp-protocol/src/pages/variables/details/Details.tsx +++ b/apps/warp-protocol/src/pages/variables/details/Details.tsx @@ -83,6 +83,13 @@ export const Details = (props: DetailsProps) => { name, value, kind, + // TODO: add init_fn and reinitialize to statics + init_fn: { + string: { + simple: value, + }, + }, + reinitialize: false, encode: false, }, }); diff --git a/apps/warp-protocol/src/pages/variables/dialogs/static/StaticVariableDialog.tsx b/apps/warp-protocol/src/pages/variables/dialogs/static/StaticVariableDialog.tsx index c56dc1b4..92f6ea0c 100644 --- a/apps/warp-protocol/src/pages/variables/dialogs/static/StaticVariableDialog.tsx +++ b/apps/warp-protocol/src/pages/variables/dialogs/static/StaticVariableDialog.tsx @@ -36,6 +36,13 @@ export const StaticVariableDialog = (props: DialogProps void; + updateFn: warp_resolver.FnValue; + setUpdateFn: (updateFn: warp_resolver.FnValue) => void; }; type Expr = diff --git a/apps/warp-protocol/src/pages/variables/update-fn/EmptyNode.tsx b/apps/warp-protocol/src/pages/variables/update-fn/EmptyNode.tsx index 4bfaa21e..1f0e3c30 100644 --- a/apps/warp-protocol/src/pages/variables/update-fn/EmptyNode.tsx +++ b/apps/warp-protocol/src/pages/variables/update-fn/EmptyNode.tsx @@ -9,7 +9,7 @@ import { DropdownMenu } from 'components/dropdown-menu/DropdownMenu'; import { warp_resolver } from '@terra-money/warp-sdk'; type EmptyNodeProps = UIElementProps & { - setUpdateFn: (updateFn: warp_resolver.UpdateFnValue) => void; + setUpdateFn: (updateFn: warp_resolver.FnValue) => void; kind: warp_resolver.VariableKind; }; @@ -24,7 +24,7 @@ export const EmptyNode = forwardRef((props: EmptyNodeProps, ref: React.Ref { - setUpdateFn({ [kind]: { simple: '' } } as warp_resolver.UpdateFnValue); + setUpdateFn({ [kind]: { simple: '' } } as warp_resolver.FnValue); }} key="value" > @@ -35,7 +35,7 @@ export const EmptyNode = forwardRef((props: EmptyNodeProps, ref: React.Ref { setUpdateFn({ [kind]: { expr: { left: { simple: '' }, op: 'add', right: { simple: '' } } }, - } as warp_resolver.UpdateFnValue); + } as warp_resolver.FnValue); }} key="expr" > diff --git a/apps/warp-protocol/src/pages/variables/update-fn/UpdateFnDialog.tsx b/apps/warp-protocol/src/pages/variables/update-fn/UpdateFnDialog.tsx index e9a74796..8f7b656f 100644 --- a/apps/warp-protocol/src/pages/variables/update-fn/UpdateFnDialog.tsx +++ b/apps/warp-protocol/src/pages/variables/update-fn/UpdateFnDialog.tsx @@ -9,13 +9,13 @@ import { useState } from 'react'; export type UpdateFnDialogProps = { kind: warp_resolver.VariableKind; - updateFn?: warp_resolver.UpdateFnValue; + updateFn?: warp_resolver.FnValue; }; -export const UpdateFnDialog = (props: DialogProps) => { +export const UpdateFnDialog = (props: DialogProps) => { const { closeDialog, updateFn, kind } = props; - const [updateFnState, setUpdateFnState] = useState(updateFn); + const [updateFnState, setUpdateFnState] = useState(updateFn); return ( @@ -50,5 +50,5 @@ export const UpdateFnDialog = (props: DialogProps { - return useDialog(UpdateFnDialog); + return useDialog(UpdateFnDialog); }; diff --git a/apps/warp-protocol/src/pages/variables/update-fn/UpdateFnNode.tsx b/apps/warp-protocol/src/pages/variables/update-fn/UpdateFnNode.tsx index e9dcb50f..56f7cde8 100644 --- a/apps/warp-protocol/src/pages/variables/update-fn/UpdateFnNode.tsx +++ b/apps/warp-protocol/src/pages/variables/update-fn/UpdateFnNode.tsx @@ -9,8 +9,8 @@ import { warp_resolver } from '@terra-money/warp-sdk'; export type UpdateFnNodeProps = UIElementProps & { kind: warp_resolver.VariableKind; - updateFn?: warp_resolver.UpdateFnValue; - setUpdateFn: (updateFn: warp_resolver.UpdateFnValue) => void; + updateFn?: warp_resolver.FnValue; + setUpdateFn: (updateFn: warp_resolver.FnValue) => void; }; export const UpdateFnNode = (props: UpdateFnNodeProps) => { diff --git a/apps/warp-protocol/src/pages/variables/update-fn/UpdateFnValueInput.tsx b/apps/warp-protocol/src/pages/variables/update-fn/UpdateFnValueInput.tsx index 055203ee..822a172c 100644 --- a/apps/warp-protocol/src/pages/variables/update-fn/UpdateFnValueInput.tsx +++ b/apps/warp-protocol/src/pages/variables/update-fn/UpdateFnValueInput.tsx @@ -12,9 +12,9 @@ import { Container } from '@terra-money/apps/components'; import { ReactComponent as PencilIcon } from 'components/assets/Pencil.svg'; interface UpdateFnValueInputProps { - value?: warp_resolver.UpdateFnValue; + value?: warp_resolver.FnValue; kind: warp_resolver.VariableKind; - onChange: (value: warp_resolver.UpdateFnValue) => void; + onChange: (value: warp_resolver.FnValue) => void; label?: string; className?: string; } diff --git a/apps/warp-protocol/src/tx/useCreateJobTx.ts b/apps/warp-protocol/src/tx/useCreateJobTx.ts index af68ae64..bce33ee7 100644 --- a/apps/warp-protocol/src/tx/useCreateJobTx.ts +++ b/apps/warp-protocol/src/tx/useCreateJobTx.ts @@ -37,10 +37,11 @@ export const useCreateJobTx = () => { name, labels: [], description, - condition: JSON.stringify(condition), vars: JSON.stringify(orderedVars), reward: reward.toString(), - msgs: JSON.stringify(msgs), + // TODO: add duration_days input field + duration_days: '30', + executions: [{ condition: JSON.stringify(condition), msgs: JSON.stringify(msgs) }], }); }, { diff --git a/apps/warp-protocol/src/types/job.ts b/apps/warp-protocol/src/types/job.ts index 1db6a019..356e2b4b 100644 --- a/apps/warp-protocol/src/types/job.ts +++ b/apps/warp-protocol/src/types/job.ts @@ -5,12 +5,14 @@ import Big from 'big.js'; export class Job { info: WarpJob; condition: warp_resolver.Condition; + msgs: warp_resolver.CosmosMsgFor_Empty[]; vars: warp_resolver.Variable[]; reward: u; constructor(info: WarpJob) { this.info = info; - this.condition = info.condition; + this.condition = info.executions[0].condition; + this.msgs = info.executions[0].msgs; this.vars = info.vars; this.reward = Big(info.reward) as u; } From 2c12c1524247c952ab8061a5456d1fea036a6a89 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Fri, 3 Nov 2023 15:35:47 +0100 Subject: [PATCH 02/33] add job fee estimate logic in create tz --- apps/warp-protocol/src/tx/useCreateJobTx.ts | 42 ++++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/apps/warp-protocol/src/tx/useCreateJobTx.ts b/apps/warp-protocol/src/tx/useCreateJobTx.ts index bce33ee7..326057f3 100644 --- a/apps/warp-protocol/src/tx/useCreateJobTx.ts +++ b/apps/warp-protocol/src/tx/useCreateJobTx.ts @@ -31,18 +31,40 @@ export const useCreateJobTx = () => { const orderedVars = orderVarsByReferencing(vars); - return sdk.tx.createJob(wallet.walletAddress, { - recurring, - requeue_on_evict: true, - name, - labels: [], - description, + const nativeTokenDenom = await sdk.nativeTokenDenom(); + const duration_days = '30'; + const executions = [{ condition: JSON.stringify(condition), msgs: JSON.stringify(msgs) }]; + const jobFeeEstimate = await sdk.estimateJobFee(wallet.walletAddress, { vars: JSON.stringify(orderedVars), - reward: reward.toString(), - // TODO: add duration_days input field - duration_days: '30', - executions: [{ condition: JSON.stringify(condition), msgs: JSON.stringify(msgs) }], + recurring: recurring, + executions, + duration_days, }); + + return sdk.tx.createJob( + wallet.walletAddress, + { + recurring, + requeue_on_evict: true, + name, + labels: [], + description, + vars: JSON.stringify(orderedVars), + // TODO: add reward estimate + reward: reward.toString(), + // TODO: add duration_days input field + duration_days, + executions, + }, + [ + { + native: { + denom: nativeTokenDenom, + amount: jobFeeEstimate.toString(), + }, + }, + ] + ); }, { txKey: TX_KEY.CREATE_JOB, From 1f25c9eb45ab5f0404ab8de9fd637d23eeb17bed Mon Sep 17 00:00:00 2001 From: simke9445 Date: Sat, 11 Nov 2023 17:55:35 +0100 Subject: [PATCH 03/33] add new sdk changes --- .../action-element/ActionElement.tsx | 13 +---- .../connected-button/ConnectedButton.tsx | 13 +---- .../connect-wallet/ConnectWalletDialog.tsx | 51 ++----------------- .../CreateAccountDialog.module.sass | 16 ------ .../connect-wallet/CreateAccountDialog.tsx | 48 ----------------- .../components/if-connected/IfConnected.tsx | 27 +--------- .../src/queries/useWarpAccount.ts | 6 +-- apps/warp-protocol/src/tx/index.ts | 1 - apps/warp-protocol/src/tx/useAddFundsTx.ts | 4 +- .../src/tx/useCreateAccountTx.ts | 20 -------- apps/warp-protocol/src/tx/useCreateJobTx.ts | 15 +++--- .../src/tx/useWithdrawFundsTx.ts | 2 +- 12 files changed, 22 insertions(+), 194 deletions(-) delete mode 100644 apps/warp-protocol/src/components/dialog/connect-wallet/CreateAccountDialog.module.sass delete mode 100644 apps/warp-protocol/src/components/dialog/connect-wallet/CreateAccountDialog.tsx delete mode 100644 apps/warp-protocol/src/tx/useCreateAccountTx.ts diff --git a/apps/warp-protocol/src/components/action-element/ActionElement.tsx b/apps/warp-protocol/src/components/action-element/ActionElement.tsx index 3a869cd7..cb1ad093 100644 --- a/apps/warp-protocol/src/components/action-element/ActionElement.tsx +++ b/apps/warp-protocol/src/components/action-element/ActionElement.tsx @@ -1,8 +1,6 @@ import { cloneElement, MouseEventHandler, useCallback } from 'react'; import { useConnectWalletDialog } from '../dialog/connect-wallet'; import { sleep } from 'utils'; -import { useWarpAccount } from 'queries/useWarpAccount'; -import { useCreateAccountDialog } from 'components/dialog/connect-wallet/CreateAccountDialog'; import { useLocalWallet } from '@terra-money/apps/hooks'; export type ActionElementProps = { @@ -14,14 +12,9 @@ export const ActionElement = (props: ActionElementProps) => { const localWallet = useLocalWallet(); const openConnectDialog = useConnectWalletDialog(); - const { data: warpAccount, isFetching: accountFetching } = useWarpAccount(); - - const openCreateAccountDialog = useCreateAccountDialog(); - const handleClick: MouseEventHandler = useCallback( async (event) => { // let connectionType: ConnectType | undefined; - let accountReady: boolean | undefined = Boolean(warpAccount) && !accountFetching; // If wallet is not connected, open connect dialog and wait for connection if (!localWallet.connectedWallet) { @@ -33,8 +26,6 @@ export const ActionElement = (props: ActionElementProps) => { // Sometimes the balance calculation is wrong // So we wait for a bit to make sure the balance is fetched correctly await sleep(200); - } else if (!accountReady) { - accountReady = await openCreateAccountDialog({}); } // If the user was already connected or just connected via extension: @@ -42,11 +33,11 @@ export const ActionElement = (props: ActionElementProps) => { // If another connection type was selected, disregard the original action // The user will have to press the button again after connecting // TODO: check if this works after removing connectionType === ConnectType.EXTENSION - if (localWallet.connectedWallet && accountReady) { + if (localWallet.connectedWallet) { action.props.onClick?.(event); } }, - [action, localWallet.connectedWallet, openConnectDialog, warpAccount, accountFetching, openCreateAccountDialog] + [action, localWallet.connectedWallet, openConnectDialog] ); return cloneElement(action, { diff --git a/apps/warp-protocol/src/components/connected-button/ConnectedButton.tsx b/apps/warp-protocol/src/components/connected-button/ConnectedButton.tsx index 836f0f4c..fad06fbb 100644 --- a/apps/warp-protocol/src/components/connected-button/ConnectedButton.tsx +++ b/apps/warp-protocol/src/components/connected-button/ConnectedButton.tsx @@ -2,8 +2,6 @@ import { Button, ButtonProps } from 'components/primitives'; import { forwardRef, MouseEventHandler, useCallback } from 'react'; import { useConnectWalletDialog } from '../dialog/connect-wallet'; import { sleep } from 'utils'; -import { useCreateAccountDialog } from 'components/dialog/connect-wallet/CreateAccountDialog'; -import { useWarpAccount } from 'queries/useWarpAccount'; import { useLocalWallet } from '@terra-money/apps/hooks'; export type ConnectedButtonProps = ButtonProps; @@ -13,14 +11,9 @@ export const ConnectedButton = forwardRef = useCallback( async (event) => { // let connectionType: ConnectType | undefined; - let accountReady: boolean | undefined = Boolean(warpAccount) && !accountFetching; // If wallet is not connected, open connect dialog and wait for connection if (!localWallet.connectedWallet) { @@ -32,8 +25,6 @@ export const ConnectedButton = forwardRef; diff --git a/apps/warp-protocol/src/components/dialog/connect-wallet/ConnectWalletDialog.tsx b/apps/warp-protocol/src/components/dialog/connect-wallet/ConnectWalletDialog.tsx index 9505f6d4..d6962c78 100644 --- a/apps/warp-protocol/src/components/dialog/connect-wallet/ConnectWalletDialog.tsx +++ b/apps/warp-protocol/src/components/dialog/connect-wallet/ConnectWalletDialog.tsx @@ -1,12 +1,9 @@ import { useWallet } from '@terra-money/wallet-kit'; import { Button, Text } from 'components/primitives'; -import { useEffect, useRef, useState } from 'react'; -import { useDialog, DialogProps, useLocalWallet } from '@terra-money/apps/hooks'; +import { useState } from 'react'; +import { useDialog, DialogProps } from '@terra-money/apps/hooks'; import { Dialog, DialogBody, DialogHeader } from 'components/dialog'; import styles from './ConnectWalletDialog.module.sass'; -import { useWarpAccount } from 'queries/useWarpAccount'; -import { useCreateAccountDialog } from './CreateAccountDialog'; -import { warp_controller } from '@terra-money/warp-sdk'; type ConnectWalletDialogProps = { title?: string; @@ -14,56 +11,14 @@ type ConnectWalletDialogProps = { }; // TODO: filter for supported available wallets +// TODO: add wallet connect export const ConnectWalletDialog = (props: DialogProps) => { const { closeDialog, title, subtitle } = props; const { connect, availableWallets } = useWallet(); - const warpAccountQuery = useWarpAccount(); - const { data: warpAccount } = warpAccountQuery; - const openCreateAccountDialog = useCreateAccountDialog(); - - const [executed, setExecuted] = useState(false); const [loading, setLoading] = useState(false); - const localWallet = useLocalWallet(); - - const warpAccountRef = useRef(); - - warpAccountRef.current = warpAccount; - - useEffect(() => { - let timeoutId: NodeJS.Timeout; - - const cb = async () => { - if (timeoutId) { - clearTimeout(timeoutId); - } - - if (localWallet.connectedWallet) { - timeoutId = setTimeout(async () => { - if (!warpAccountRef.current && !executed) { - setExecuted(true); - const resp = await openCreateAccountDialog({}); - - if (resp) { - closeDialog(true, { closeAll: true }); - } - } - - if (warpAccountRef.current) { - closeDialog(true, { closeAll: true }); - } - }, 400); - } - }; - - cb(); - - // Clear the timeout if the component re-renders or unmounts - return () => clearTimeout(timeoutId); - }, [warpAccountRef, localWallet.connectedWallet, closeDialog, openCreateAccountDialog, setExecuted, executed]); - return ( closeDialog(undefined, { closeAll: true })} /> diff --git a/apps/warp-protocol/src/components/dialog/connect-wallet/CreateAccountDialog.module.sass b/apps/warp-protocol/src/components/dialog/connect-wallet/CreateAccountDialog.module.sass deleted file mode 100644 index 534d6cc4..00000000 --- a/apps/warp-protocol/src/components/dialog/connect-wallet/CreateAccountDialog.module.sass +++ /dev/null @@ -1,16 +0,0 @@ -.root - -.body - row-gap: 16px !important - -.subtitle - margin-bottom: 32px - -.btn - width: 100% - -.description - line-height: 22px - -.transaction - margin-top: 16px \ No newline at end of file diff --git a/apps/warp-protocol/src/components/dialog/connect-wallet/CreateAccountDialog.tsx b/apps/warp-protocol/src/components/dialog/connect-wallet/CreateAccountDialog.tsx deleted file mode 100644 index 33535cd3..00000000 --- a/apps/warp-protocol/src/components/dialog/connect-wallet/CreateAccountDialog.tsx +++ /dev/null @@ -1,48 +0,0 @@ -import { Button, Text } from 'components/primitives'; -import { useDialog, DialogProps } from '@terra-money/apps/hooks'; -import { Dialog, DialogBody, DialogFooter, DialogHeader } from 'components/dialog'; -import styles from './CreateAccountDialog.module.sass'; -import { useCreateAccountTx } from 'tx'; - -type CreateAccountDialogProps = {}; - -export const CreateAccountDialog = (props: DialogProps) => { - const { closeDialog } = props; - - const [txResult, createAccountTx] = useCreateAccountTx(); - - return ( - - closeDialog(undefined, { closeAll: true })} /> - - - Account represents your own virtual wallet used for interacting with Warp. Managed as a typical wallet, you - can view and organize your token balances within "Balances" tab. - - - A transaction on your behalf is required to set up your Warp account. - - - - - - - ); -}; - -export const useCreateAccountDialog = () => { - return useDialog(CreateAccountDialog); -}; diff --git a/apps/warp-protocol/src/components/if-connected/IfConnected.tsx b/apps/warp-protocol/src/components/if-connected/IfConnected.tsx index 2fa6d767..6f1f546f 100644 --- a/apps/warp-protocol/src/components/if-connected/IfConnected.tsx +++ b/apps/warp-protocol/src/components/if-connected/IfConnected.tsx @@ -1,11 +1,8 @@ -import { Container } from '@terra-money/apps/components'; import { LocalWallet, useLocalWallet } from '@terra-money/apps/hooks'; import { useWallet, WalletStatus } from '@terra-money/wallet-kit'; import { NotConnected } from 'components/not-connected'; -import { Button, Text, Throbber } from 'components/primitives'; -import { useWarpAccount } from 'queries/useWarpAccount'; +import { Throbber } from 'components/primitives'; import { ReactNode } from 'react'; -import { useCreateAccountTx } from 'tx'; import styles from './IfConnected.module.sass'; interface IfConnectedProps { @@ -20,10 +17,7 @@ export const IfConnected = (props: IfConnectedProps) => { const localWallet = useLocalWallet(); const wallet = useWallet(); - const { data: warpAccount, isLoading: isWarpAccountLoading } = useWarpAccount(); - const [txResult, createAccountTx] = useCreateAccountTx(); - - if (wallet.status === WalletStatus.INITIALIZING || isWarpAccountLoading) { + if (wallet.status === WalletStatus.INITIALIZING) { return hideLoader ? null : ; } @@ -31,22 +25,5 @@ export const IfConnected = (props: IfConnectedProps) => { return <>{elseChildren}; } - if (!warpAccount) { - return ( - - In order to use Warp, please create an account. - - - ); - } - return <>{typeof thenChildren === 'function' ? thenChildren(localWallet) : thenChildren}; }; diff --git a/apps/warp-protocol/src/queries/useWarpAccount.ts b/apps/warp-protocol/src/queries/useWarpAccount.ts index f89530dd..9fa64d6b 100644 --- a/apps/warp-protocol/src/queries/useWarpAccount.ts +++ b/apps/warp-protocol/src/queries/useWarpAccount.ts @@ -4,7 +4,7 @@ import { warp_controller } from '@terra-money/warp-sdk'; import { QUERY_KEY } from './queryKey'; import { useWarpSdk } from '@terra-money/apps/hooks'; -export const useWarpAccount = (): UseQueryResult => { +export const useWarpAccount = (): UseQueryResult => { const { connectedWallet, chainId } = useLocalWallet(); const sdk = useWarpSdk(); @@ -15,7 +15,7 @@ export const useWarpAccount = (): UseQueryResult; + return query as UseQueryResult; }; diff --git a/apps/warp-protocol/src/tx/index.ts b/apps/warp-protocol/src/tx/index.ts index 3348ba71..62bec3f6 100644 --- a/apps/warp-protocol/src/tx/index.ts +++ b/apps/warp-protocol/src/tx/index.ts @@ -4,7 +4,6 @@ export * from './useEditJobTx'; export * from './useExecuteJobTx'; export * from './useAddFundsTx'; export * from './useWithdrawFundsTx'; -export * from './useCreateAccountTx'; export * from './useCreateTemplateTx'; export * from './useDeleteTemplateTx'; export * from './useEditTemplateTx'; diff --git a/apps/warp-protocol/src/tx/useAddFundsTx.ts b/apps/warp-protocol/src/tx/useAddFundsTx.ts index 32130899..0b3f701a 100644 --- a/apps/warp-protocol/src/tx/useAddFundsTx.ts +++ b/apps/warp-protocol/src/tx/useAddFundsTx.ts @@ -13,14 +13,14 @@ interface AddFundsTxProps { } export const useAddFundsTx = () => { - const { data: account = {} as warp_controller.Account } = useWarpAccount(); + const { data: account = {} as warp_controller.LegacyAccount } = useWarpAccount(); const sdk = useWarpSdk(); return useTx( async (options) => { const { token, amount } = options; - return sdk.tx.depositToAccount(account.owner, account.account, token, amount.toString()); + return sdk.tx.legacyDepositToAccount(account.owner, account.account, token, amount.toString()); }, { txKey: TX_KEY.ADD_FUNDS, diff --git a/apps/warp-protocol/src/tx/useCreateAccountTx.ts b/apps/warp-protocol/src/tx/useCreateAccountTx.ts deleted file mode 100644 index 575dea46..00000000 --- a/apps/warp-protocol/src/tx/useCreateAccountTx.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { useTx } from '@terra-money/apps/libs/transactions'; -import { useWarpSdk } from '@terra-money/apps/hooks'; -import { TX_KEY } from './txKey'; - -export interface CreateAccountTxProps {} - -export const useCreateAccountTx = () => { - const sdk = useWarpSdk(); - - return useTx( - async (options) => { - const { wallet } = options; - - return sdk.tx.createAccount(wallet.walletAddress); - }, - { - txKey: TX_KEY.CREATE_ACCOUNT, - } - ); -}; diff --git a/apps/warp-protocol/src/tx/useCreateJobTx.ts b/apps/warp-protocol/src/tx/useCreateJobTx.ts index 326057f3..f99077ef 100644 --- a/apps/warp-protocol/src/tx/useCreateJobTx.ts +++ b/apps/warp-protocol/src/tx/useCreateJobTx.ts @@ -31,7 +31,6 @@ export const useCreateJobTx = () => { const orderedVars = orderVarsByReferencing(vars); - const nativeTokenDenom = await sdk.nativeTokenDenom(); const duration_days = '30'; const executions = [{ condition: JSON.stringify(condition), msgs: JSON.stringify(msgs) }]; const jobFeeEstimate = await sdk.estimateJobFee(wallet.walletAddress, { @@ -41,11 +40,15 @@ export const useCreateJobTx = () => { duration_days, }); + // TODO: + // - add ui for depositing assets + // - extend useCreateJobTx with deposits + // - add estimate fee options + UI + return sdk.tx.createJob( wallet.walletAddress, { recurring, - requeue_on_evict: true, name, labels: [], description, @@ -57,12 +60,8 @@ export const useCreateJobTx = () => { executions, }, [ - { - native: { - denom: nativeTokenDenom, - amount: jobFeeEstimate.toString(), - }, - }, + jobFeeEstimate, + // TODO: add deposits ] ); }, diff --git a/apps/warp-protocol/src/tx/useWithdrawFundsTx.ts b/apps/warp-protocol/src/tx/useWithdrawFundsTx.ts index 2bfc2c01..f121af1a 100644 --- a/apps/warp-protocol/src/tx/useWithdrawFundsTx.ts +++ b/apps/warp-protocol/src/tx/useWithdrawFundsTx.ts @@ -16,7 +16,7 @@ export const useWithdrawFundsTx = () => { async (options) => { const { token, amount, wallet } = options; - return sdk.tx.withdrawFromAccount(wallet.walletAddress, wallet.walletAddress, token, amount.toString()); + return sdk.tx.legacyWithdrawFromAccount(wallet.walletAddress, wallet.walletAddress, token, amount.toString()); }, { txKey: TX_KEY.WITHDRAW_FUNDS, From 3612fa7849b38139331d8e8f3afc9c068e91b178 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Thu, 30 Nov 2023 16:42:05 +0100 Subject: [PATCH 04/33] new sdk estimate logic --- apps/warp-protocol/src/tx/useCreateJobTx.ts | 72 +++++++++++---------- apps/warp-protocol/src/types/job.ts | 2 +- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/apps/warp-protocol/src/tx/useCreateJobTx.ts b/apps/warp-protocol/src/tx/useCreateJobTx.ts index f99077ef..cd92b49e 100644 --- a/apps/warp-protocol/src/tx/useCreateJobTx.ts +++ b/apps/warp-protocol/src/tx/useCreateJobTx.ts @@ -1,16 +1,13 @@ import { useTx } from '@terra-money/apps/libs/transactions'; -import { u } from '@terra-money/apps/types'; -import Big from 'big.js'; import { TX_KEY } from './txKey'; import { containsAllReferencedVars, orderVarsByReferencing } from 'utils/msgs'; import { useWarpSdk } from '@terra-money/apps/hooks'; -import { warp_resolver } from '@terra-money/warp-sdk'; +import { composers, warp_resolver } from '@terra-money/warp-sdk'; export interface CreateJobTxProps { name: string; - reward: u; description: string; - msgs: warp_resolver.CosmosMsgFor_Empty[]; + msgs: warp_resolver.WarpMsg[]; vars: warp_resolver.Variable[]; condition: warp_resolver.Condition; recurring: boolean; @@ -21,7 +18,7 @@ export const useCreateJobTx = () => { return useTx( async (options) => { - const { wallet, reward, name, msgs, condition, vars, description, recurring } = options; + const { wallet, name, msgs, condition, vars, description, recurring } = options; if (!containsAllReferencedVars(vars, msgs, condition)) { throw Error( @@ -29,41 +26,48 @@ export const useCreateJobTx = () => { ); } - const orderedVars = orderVarsByReferencing(vars); - - const duration_days = '30'; - const executions = [{ condition: JSON.stringify(condition), msgs: JSON.stringify(msgs) }]; - const jobFeeEstimate = await sdk.estimateJobFee(wallet.walletAddress, { - vars: JSON.stringify(orderedVars), - recurring: recurring, - executions, - duration_days, - }); - // TODO: // - add ui for depositing assets // - extend useCreateJobTx with deposits // - add estimate fee options + UI - return sdk.tx.createJob( + const orderedVars = orderVarsByReferencing(vars); + const durationDays = '30'; + const executions = [{ condition, msgs }]; + + const estimateJobRewardMsg = composers.job + .estimate() + .recurring(recurring) + .durationDays(durationDays) + .vars(orderedVars) + .executions(executions) + .compose(); + + const reward = await sdk.estimateJobReward(wallet.walletAddress, estimateJobRewardMsg); + + const operationalAmount = await sdk.estimateJobFee( wallet.walletAddress, - { - recurring, - name, - labels: [], - description, - vars: JSON.stringify(orderedVars), - // TODO: add reward estimate - reward: reward.toString(), - // TODO: add duration_days input field - duration_days, - executions, - }, - [ - jobFeeEstimate, - // TODO: add deposits - ] + estimateJobRewardMsg, + reward.amount.toString() ); + + const createJobMsg = composers.job + .create() + .name(name) + .reward(reward.amount.toString()) + .operationalAmount(operationalAmount.amount.toString()) + .recurring(recurring) + .description(description) + .labels([]) + .vars(orderedVars) + .durationDays(durationDays) + .executions(executions) + .compose(); + + return sdk.tx.createJob(wallet.walletAddress, createJobMsg, [ + operationalAmount, + // TODO: add deposits + ]); }, { txKey: TX_KEY.CREATE_JOB, diff --git a/apps/warp-protocol/src/types/job.ts b/apps/warp-protocol/src/types/job.ts index 356e2b4b..7fb747ef 100644 --- a/apps/warp-protocol/src/types/job.ts +++ b/apps/warp-protocol/src/types/job.ts @@ -5,7 +5,7 @@ import Big from 'big.js'; export class Job { info: WarpJob; condition: warp_resolver.Condition; - msgs: warp_resolver.CosmosMsgFor_Empty[]; + msgs: warp_resolver.WarpMsg[]; vars: warp_resolver.Variable[]; reward: u; From f5bc48df7b9b00989c5423661d1bf35d988dd351 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Mon, 4 Dec 2023 17:37:12 +0100 Subject: [PATCH 05/33] port msg and variable usage to new contracts (WIP) --- .../src/pages/job-new/JobNew.tsx | 31 +++++++------- .../src/pages/job-new/useJobStorage.ts | 40 ++++++++++++------- .../src/pages/template-new/TemplateNew.tsx | 2 +- .../src/tx/useCreateTemplateTx.ts | 2 +- apps/warp-protocol/src/utils/msgs.ts | 10 ++--- 5 files changed, 47 insertions(+), 38 deletions(-) diff --git a/apps/warp-protocol/src/pages/job-new/JobNew.tsx b/apps/warp-protocol/src/pages/job-new/JobNew.tsx index 80621d37..8520d52d 100644 --- a/apps/warp-protocol/src/pages/job-new/JobNew.tsx +++ b/apps/warp-protocol/src/pages/job-new/JobNew.tsx @@ -1,5 +1,4 @@ import { UIElementProps } from '@terra-money/apps/components'; -import { microfy } from '@terra-money/apps/libs/formatting'; import { useLocalWallet } from '@terra-money/apps/hooks'; import { IfConnected } from 'components/if-connected'; import { Throbber } from 'components/primitives'; @@ -16,7 +15,6 @@ import { useMemo } from 'react'; import { CachedVariablesSession } from './CachedVariablesSession'; import { DeveloperForm } from './developer-form/DeveloperForm'; import { filterUnreferencedVariables } from 'utils/msgs'; -import { useNativeToken } from 'hooks/useNativeToken'; type JobNewProps = UIElementProps & {}; @@ -34,8 +32,6 @@ export const JobNew = (props: JobNewProps) => { const mode = searchParams.get('mode') ?? 'advanced'; - const nativeToken = useNativeToken(); - return (
@@ -66,7 +62,6 @@ export const JobNew = (props: JobNewProps) => { const { template = {} as warp_templates.Template, name, - reward, message, description, variables, @@ -82,7 +77,6 @@ export const JobNew = (props: JobNewProps) => { vars, description, recurring, - reward: microfy(reward, nativeToken.decimals), msgs, condition: condition!, }); @@ -107,7 +101,7 @@ export const JobNew = (props: JobNewProps) => { onNext={async (props) => { if (detailsInput) { const { cond, variables } = props; - const { name, reward, message, description, recurring } = detailsInput; + const { name, message, description, recurring } = detailsInput; const msgs = parseMsgs(message); @@ -117,7 +111,6 @@ export const JobNew = (props: JobNewProps) => { name, vars, description, - reward: microfy(reward, nativeToken.decimals), msgs, recurring, condition: cond, @@ -144,28 +137,32 @@ export const JobNew = (props: JobNewProps) => { ); }; -export const decodeMsgs = (msgs: warp_resolver.CosmosMsgFor_Empty[]) => { +export const decodeMsgs = (msgs: warp_resolver.WarpMsg[]) => { return msgs.map(decodeMsg); }; -export const encodeMsgs = (value: string): warp_resolver.CosmosMsgFor_Empty[] => { +export const encodeMsgs = (value: string): warp_resolver.WarpMsg[] => { const msgs = parseMsgs(value); return msgs.map(encodeMsg); }; -export const parseMsgs = (value: string): warp_resolver.CosmosMsgFor_Empty[] => { +export const parseMsgs = (value: string): warp_resolver.WarpMsg[] => { const parsed = JSON.parse(value); - const msgs: warp_resolver.CosmosMsgFor_Empty[] = Array.isArray(parsed) - ? (parsed as warp_resolver.CosmosMsgFor_Empty[]) - : [parsed]; + const msgs: warp_resolver.WarpMsg[] = Array.isArray(parsed) ? (parsed as warp_resolver.WarpMsg[]) : [parsed]; return msgs; }; -export const encodeMsg = (input: warp_resolver.CosmosMsgFor_Empty): warp_resolver.CosmosMsgFor_Empty => { +export const encodeMsg = (inputMsg: warp_resolver.WarpMsg): warp_resolver.WarpMsg => { + if (!('generic' in inputMsg)) { + return inputMsg; + } + + const input = inputMsg.generic; + if (!('wasm' in input)) { - return input; + return inputMsg; } let msg = input.wasm; @@ -182,7 +179,7 @@ export const encodeMsg = (input: warp_resolver.CosmosMsgFor_Empty): warp_resolve msg.migrate.msg = base64encode(msg.migrate.msg); } - return { wasm: msg }; + return { generic: { wasm: msg } }; }; const base64encode = (input: string): string => { diff --git a/apps/warp-protocol/src/pages/job-new/useJobStorage.ts b/apps/warp-protocol/src/pages/job-new/useJobStorage.ts index a23299ec..f17303b4 100644 --- a/apps/warp-protocol/src/pages/job-new/useJobStorage.ts +++ b/apps/warp-protocol/src/pages/job-new/useJobStorage.ts @@ -73,14 +73,22 @@ export const useJobStorage = () => { ); }; -export const decodeMsg = (msg: warp_resolver.CosmosMsgFor_Empty) => { +export const decodeMsg = (inputMsg: warp_resolver.WarpMsg) => { + if (!('generic' in inputMsg)) { + return inputMsg; + } + + const msg = inputMsg.generic; + if ('wasm' in msg) { if ('execute' in msg.wasm) { return { - wasm: { - execute: { - ...msg.wasm.execute, - msg: safeFromBase64(msg.wasm.execute.msg), + generic: { + wasm: { + execute: { + ...msg.wasm.execute, + msg: safeFromBase64(msg.wasm.execute.msg), + }, }, }, }; @@ -88,10 +96,12 @@ export const decodeMsg = (msg: warp_resolver.CosmosMsgFor_Empty) => { if ('instantiate' in msg.wasm) { return { - wasm: { - instantiate: { - ...msg.wasm.instantiate, - msg: safeFromBase64(msg.wasm.instantiate.msg), + generic: { + wasm: { + instantiate: { + ...msg.wasm.instantiate, + msg: safeFromBase64(msg.wasm.instantiate.msg), + }, }, }, }; @@ -99,17 +109,19 @@ export const decodeMsg = (msg: warp_resolver.CosmosMsgFor_Empty) => { if ('migrate' in msg.wasm) { return { - wasm: { - migrate: { - ...msg.wasm.migrate, - msg: safeFromBase64(msg.wasm.migrate.msg), + generic: { + wasm: { + migrate: { + ...msg.wasm.migrate, + msg: safeFromBase64(msg.wasm.migrate.msg), + }, }, }, }; } } - return msg; + return inputMsg; }; export const fromBase64 = (value: string) => { diff --git a/apps/warp-protocol/src/pages/template-new/TemplateNew.tsx b/apps/warp-protocol/src/pages/template-new/TemplateNew.tsx index c5ea99b6..78f18a52 100644 --- a/apps/warp-protocol/src/pages/template-new/TemplateNew.tsx +++ b/apps/warp-protocol/src/pages/template-new/TemplateNew.tsx @@ -108,7 +108,7 @@ export const TemplateNew = (props: TemplateNewProps) => { const extractUsedVariables = ( formattedStr: string, - msgs: warp_resolver.CosmosMsgFor_Empty[], + msgs: warp_resolver.WarpMsg[], vars: warp_resolver.Variable[], condition?: warp_resolver.Condition ) => { diff --git a/apps/warp-protocol/src/tx/useCreateTemplateTx.ts b/apps/warp-protocol/src/tx/useCreateTemplateTx.ts index 6e99fc5b..17e1b422 100644 --- a/apps/warp-protocol/src/tx/useCreateTemplateTx.ts +++ b/apps/warp-protocol/src/tx/useCreateTemplateTx.ts @@ -6,7 +6,7 @@ import { warp_resolver } from '@terra-money/warp-sdk'; export type CreateTemplateTxProps = { condition?: warp_resolver.Condition | null; formatted_str: string; - msgs: warp_resolver.CosmosMsgFor_Empty[]; + msgs: warp_resolver.WarpMsg[]; name: string; vars: warp_resolver.Variable[]; }; diff --git a/apps/warp-protocol/src/utils/msgs.ts b/apps/warp-protocol/src/utils/msgs.ts index 2af28bd1..4825f13b 100644 --- a/apps/warp-protocol/src/utils/msgs.ts +++ b/apps/warp-protocol/src/utils/msgs.ts @@ -5,7 +5,7 @@ import { warp_resolver } from '@terra-money/warp-sdk'; export function filterUnreferencedVariables( vars: warp_resolver.Variable[], - msgs: warp_resolver.CosmosMsgFor_Empty[], + msgs: warp_resolver.WarpMsg[], condition?: warp_resolver.Condition ): warp_resolver.Variable[] { const referencedVars = extractReferencedVarNames(vars, msgs, condition); @@ -17,7 +17,7 @@ export function filterUnreferencedVariables( export function containsAllReferencedVars( vars: warp_resolver.Variable[], - msgs: warp_resolver.CosmosMsgFor_Empty[], + msgs: warp_resolver.WarpMsg[], condition?: warp_resolver.Condition ): boolean { const referencedVars = extractReferencedVarNames(vars, msgs, condition); @@ -27,13 +27,13 @@ export function containsAllReferencedVars( export function extractReferencedVarNames( vars: warp_resolver.Variable[], - msgs: warp_resolver.CosmosMsgFor_Empty[], + msgs: warp_resolver.WarpMsg[], condition?: warp_resolver.Condition ): string[] { const referencedVars: Set = new Set(); const unreferencedVars: Set = new Set(vars.map((v) => variableName(v))); - msgs.forEach((msg) => scanForReferencesForCosmosMsg(msg).forEach((varName) => referencedVars.add(varName))); + msgs.forEach((msg) => scanForReferencesForWarpMsg(msg).forEach((varName) => referencedVars.add(varName))); vars.forEach((v) => { if ('query' in v) { @@ -73,7 +73,7 @@ export const scanForReferences = (obj: any): string[] => { return res; }; -const scanForReferencesForCosmosMsg = (msg: warp_resolver.CosmosMsgFor_Empty): string[] => { +const scanForReferencesForWarpMsg = (msg: warp_resolver.WarpMsg): string[] => { const obj = decodeMsg(msg); return scanForReferences(obj); }; From 2cdd6d82eb8dbac616c71d52a81e6aed347982c6 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Mon, 11 Dec 2023 12:20:35 +0100 Subject: [PATCH 06/33] placeholder account impl --- apps/warp-protocol/src/queries/useWarpAccount.ts | 13 ++++++------- apps/warp-protocol/src/tx/useAddFundsTx.ts | 8 +++++--- apps/warp-protocol/src/tx/useCreateTemplateTx.ts | 4 ++-- apps/warp-protocol/src/tx/useWithdrawFundsTx.ts | 9 ++++++++- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/apps/warp-protocol/src/queries/useWarpAccount.ts b/apps/warp-protocol/src/queries/useWarpAccount.ts index 9fa64d6b..bcc1df1b 100644 --- a/apps/warp-protocol/src/queries/useWarpAccount.ts +++ b/apps/warp-protocol/src/queries/useWarpAccount.ts @@ -1,12 +1,10 @@ import { useLocalWallet } from '@terra-money/apps/hooks'; import { useQuery, UseQueryResult } from 'react-query'; -import { warp_controller } from '@terra-money/warp-sdk'; +import { warp_account_tracker } from '@terra-money/warp-sdk'; import { QUERY_KEY } from './queryKey'; -import { useWarpSdk } from '@terra-money/apps/hooks'; -export const useWarpAccount = (): UseQueryResult => { +export const useWarpAccount = (): UseQueryResult => { const { connectedWallet, chainId } = useLocalWallet(); - const sdk = useWarpSdk(); const query = useQuery( [QUERY_KEY.WARP_ACCOUNT, chainId, connectedWallet?.walletAddress], @@ -15,9 +13,10 @@ export const useWarpAccount = (): UseQueryResult; + return query as UseQueryResult; }; diff --git a/apps/warp-protocol/src/tx/useAddFundsTx.ts b/apps/warp-protocol/src/tx/useAddFundsTx.ts index 0b3f701a..6393e5d4 100644 --- a/apps/warp-protocol/src/tx/useAddFundsTx.ts +++ b/apps/warp-protocol/src/tx/useAddFundsTx.ts @@ -5,7 +5,7 @@ import Big from 'big.js'; import { u } from '@terra-money/apps/types'; import { useWarpAccount } from 'queries/useWarpAccount'; import { useWarpSdk } from '@terra-money/apps/hooks'; -import { warp_controller } from '@terra-money/warp-sdk'; +import { warp_account_tracker } from '@terra-money/warp-sdk'; interface AddFundsTxProps { token: Token; @@ -13,14 +13,16 @@ interface AddFundsTxProps { } export const useAddFundsTx = () => { - const { data: account = {} as warp_controller.LegacyAccount } = useWarpAccount(); + const { data: account = {} as warp_account_tracker.Account } = useWarpAccount(); const sdk = useWarpSdk(); return useTx( async (options) => { const { token, amount } = options; - return sdk.tx.legacyDepositToAccount(account.owner, account.account, token, amount.toString()); + // TODO: implement + + return sdk.tx.depositToAccount(account.addr, account.addr, token, amount.toString()); }, { txKey: TX_KEY.ADD_FUNDS, diff --git a/apps/warp-protocol/src/tx/useCreateTemplateTx.ts b/apps/warp-protocol/src/tx/useCreateTemplateTx.ts index 17e1b422..ce28cf62 100644 --- a/apps/warp-protocol/src/tx/useCreateTemplateTx.ts +++ b/apps/warp-protocol/src/tx/useCreateTemplateTx.ts @@ -18,12 +18,12 @@ export const useCreateTemplateTx = () => { async (options) => { const { wallet, formatted_str, vars, name, msgs, condition } = options; + // TODO: implement return sdk.tx.submitTemplate(wallet.walletAddress, { formatted_str, - condition, + executions: [{ condition: JSON.stringify(condition), msgs: JSON.stringify(msgs) }], vars, name, - msg: JSON.stringify(msgs), }); }, { diff --git a/apps/warp-protocol/src/tx/useWithdrawFundsTx.ts b/apps/warp-protocol/src/tx/useWithdrawFundsTx.ts index f121af1a..4cb31903 100644 --- a/apps/warp-protocol/src/tx/useWithdrawFundsTx.ts +++ b/apps/warp-protocol/src/tx/useWithdrawFundsTx.ts @@ -15,8 +15,15 @@ export const useWithdrawFundsTx = () => { return useTx( async (options) => { const { token, amount, wallet } = options; + // TODO: implement - return sdk.tx.legacyWithdrawFromAccount(wallet.walletAddress, wallet.walletAddress, token, amount.toString()); + return sdk.tx.withdrawFromAccount( + wallet.walletAddress, + wallet.walletAddress, + wallet.walletAddress, + token, + amount.toString() + ); }, { txKey: TX_KEY.WITHDRAW_FUNDS, From 08ae727ea1d02dbdb4be361f12f261cc705a1494 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Mon, 11 Dec 2023 12:30:51 +0100 Subject: [PATCH 07/33] placeholders --- .../src/pages/balances/BalanceCard.tsx | 5 ++-- .../src/pages/job-new/JobNew.tsx | 5 ++-- .../template-form/TemplateForm.tsx | 9 ++++--- .../templates-input/TemplatesInput.tsx | 8 +++--- .../job-new/details-form/useDetailsForm.ts | 4 +-- .../src/pages/job-new/useJobStorage.ts | 5 ++-- .../pages/template-new/useTemplateNewForm.ts | 7 ++--- .../src/pages/templates/TemplateCard.tsx | 4 +-- .../edit-template/EditTemplateDialog.tsx | 4 +-- .../edit-template/useEditTemplateForm.ts | 4 +-- .../src/queries/useTemplatesQuery.ts | 9 +++---- apps/warp-protocol/src/types/index.ts | 1 + apps/warp-protocol/src/types/template.ts | 26 +++++++++++++++++++ apps/warp-protocol/src/utils/variable.ts | 5 ++-- 14 files changed, 64 insertions(+), 32 deletions(-) create mode 100644 apps/warp-protocol/src/types/template.ts diff --git a/apps/warp-protocol/src/pages/balances/BalanceCard.tsx b/apps/warp-protocol/src/pages/balances/BalanceCard.tsx index 1d89cc87..6410a5f9 100644 --- a/apps/warp-protocol/src/pages/balances/BalanceCard.tsx +++ b/apps/warp-protocol/src/pages/balances/BalanceCard.tsx @@ -26,10 +26,11 @@ export const BalanceCard = (props: BalanceCardProps) => { balance ); - const { data: warpAccount = { account: walletAddr }, isLoading: isWarpAccountLoading } = useWarpAccount(); + const { data: warpAccount = { addr: walletAddr }, isLoading: isWarpAccountLoading } = useWarpAccount(); + // TODO: implement const { data: warpBalance = Big(0) as u, isLoading: isWarpBalanceLoading } = useTokenBalanceQuery( - warpAccount.account, + warpAccount.addr, balance ); diff --git a/apps/warp-protocol/src/pages/job-new/JobNew.tsx b/apps/warp-protocol/src/pages/job-new/JobNew.tsx index 8520d52d..4b97d038 100644 --- a/apps/warp-protocol/src/pages/job-new/JobNew.tsx +++ b/apps/warp-protocol/src/pages/job-new/JobNew.tsx @@ -4,7 +4,7 @@ import { IfConnected } from 'components/if-connected'; import { Throbber } from 'components/primitives'; import { Navigate, Route, Routes, useNavigate } from 'react-router'; import { useCreateJobTx } from 'tx/useCreateJobTx'; -import { warp_resolver, warp_templates } from '@terra-money/warp-sdk'; +import { warp_resolver } from '@terra-money/warp-sdk'; import { ConditionForm } from './condition-form/ConditionForm'; import { DetailsForm } from './details-form/DetailsForm'; import styles from './JobNew.module.sass'; @@ -15,6 +15,7 @@ import { useMemo } from 'react'; import { CachedVariablesSession } from './CachedVariablesSession'; import { DeveloperForm } from './developer-form/DeveloperForm'; import { filterUnreferencedVariables } from 'utils/msgs'; +import { Template } from 'types'; type JobNewProps = UIElementProps & {}; @@ -60,7 +61,7 @@ export const JobNew = (props: JobNewProps) => { navigate('/job-new/condition'); } else { const { - template = {} as warp_templates.Template, + template = {} as Template, name, message, description, diff --git a/apps/warp-protocol/src/pages/job-new/details-form/template-form/TemplateForm.tsx b/apps/warp-protocol/src/pages/job-new/details-form/template-form/TemplateForm.tsx index b26a8596..9e0666c9 100644 --- a/apps/warp-protocol/src/pages/job-new/details-form/template-form/TemplateForm.tsx +++ b/apps/warp-protocol/src/pages/job-new/details-form/template-form/TemplateForm.tsx @@ -8,8 +8,9 @@ import { TemplateVarInput } from '../template-var-input/TemplateVarInput'; import { findVariablePath, templateVariables } from 'utils/variable'; import { EditorInput } from 'forms/QueryExprForm/EditorInput'; import { decodeMsgs, encodeMsg, parseMsgs } from 'pages/job-new/JobNew'; +import { Template } from 'types'; -const composeMsgFromTemplate = (template: warp_templates.Template): string => { +const composeMsgFromTemplate = (template: Template): string => { const vars = templateVariables(template); let msgs = decodeMsgs(parseMsgs(template.msg)); @@ -37,10 +38,10 @@ const composeMsgFromTemplate = (template: warp_templates.Template): string => { type TemplateFormProps = { onMessageComposed: (message: string) => void; - template?: warp_templates.Template; - setTemplate: (template: warp_templates.Template | undefined) => void; + template?: Template; + setTemplate: (template: Template | undefined) => void; setTemplateVars: (vars: warp_templates.StaticVariable[]) => void; - options: warp_templates.Template[]; + options: Template[]; }; export const TemplateForm = (props: TemplateFormProps) => { diff --git a/apps/warp-protocol/src/pages/job-new/details-form/templates-input/TemplatesInput.tsx b/apps/warp-protocol/src/pages/job-new/details-form/templates-input/TemplatesInput.tsx index 5ee8cb20..74c702c1 100644 --- a/apps/warp-protocol/src/pages/job-new/details-form/templates-input/TemplatesInput.tsx +++ b/apps/warp-protocol/src/pages/job-new/details-form/templates-input/TemplatesInput.tsx @@ -7,14 +7,14 @@ import { FormControl } from 'components/form-control/FormControl'; import { DropdownMenu } from 'components/dropdown-menu/DropdownMenu'; import { useRef, useState } from 'react'; import { useInterval } from 'usehooks-ts'; -import { warp_templates } from '@terra-money/warp-sdk'; +import { Template } from 'types'; type TemplatesInputProps = UIElementProps & { - value?: warp_templates.Template | null; + value?: Template | null; label: string; - options: warp_templates.Template[]; + options: Template[]; placeholder: string; - onChange: (value: warp_templates.Template | undefined) => void; + onChange: (value: Template | undefined) => void; }; export function TemplatesInput(props: TemplatesInputProps) { diff --git a/apps/warp-protocol/src/pages/job-new/details-form/useDetailsForm.ts b/apps/warp-protocol/src/pages/job-new/details-form/useDetailsForm.ts index 652e8660..0fb15d1e 100644 --- a/apps/warp-protocol/src/pages/job-new/details-form/useDetailsForm.ts +++ b/apps/warp-protocol/src/pages/job-new/details-form/useDetailsForm.ts @@ -13,9 +13,9 @@ import { Token, u } from '@terra-money/apps/types'; import Big from 'big.js'; import { useMemo } from 'react'; import { isEmpty } from 'lodash'; -import { warp_templates } from '@terra-money/warp-sdk'; import { templateVariables } from 'utils/variable'; import { useNativeToken } from 'hooks/useNativeToken'; +import { Template } from 'types'; export interface DetailsFormInput { name: string; @@ -23,7 +23,7 @@ export interface DetailsFormInput { reward: string; message: string; recurring: boolean; - template?: warp_templates.Template; + template?: Template; selectedTabType?: 'template' | 'message'; } diff --git a/apps/warp-protocol/src/pages/job-new/useJobStorage.ts b/apps/warp-protocol/src/pages/job-new/useJobStorage.ts index f17303b4..1632344a 100644 --- a/apps/warp-protocol/src/pages/job-new/useJobStorage.ts +++ b/apps/warp-protocol/src/pages/job-new/useJobStorage.ts @@ -6,8 +6,9 @@ import { Job } from 'types/job'; import { DetailsFormInput } from './details-form/useDetailsForm'; import { useCachedVariables } from './useCachedVariables'; import { useNativeToken } from 'hooks/useNativeToken'; -import { warp_resolver, warp_templates } from '@terra-money/warp-sdk'; +import { warp_resolver } from '@terra-money/warp-sdk'; import { useChainSuffix } from '@terra-money/apps/hooks'; +import { Template } from 'types'; export const useJobStorage = () => { const detailsInputKey = useChainSuffix('__warp_details_input'); @@ -44,7 +45,7 @@ export const useJobStorage = () => { ); const setJobTemplate = useCallback( - (template: warp_templates.Template) => { + (template: Template) => { const details: DetailsFormInput = { reward: '', description: '', diff --git a/apps/warp-protocol/src/pages/template-new/useTemplateNewForm.ts b/apps/warp-protocol/src/pages/template-new/useTemplateNewForm.ts index b0841721..f4a64454 100644 --- a/apps/warp-protocol/src/pages/template-new/useTemplateNewForm.ts +++ b/apps/warp-protocol/src/pages/template-new/useTemplateNewForm.ts @@ -1,10 +1,11 @@ import { FormFunction, FormInput, FormState, useForm } from '@terra-money/apps/hooks'; import { useMemo } from 'react'; import { isEmpty } from 'lodash'; -import { warp_resolver, warp_templates } from '@terra-money/warp-sdk'; +import { warp_resolver } from '@terra-money/warp-sdk'; import { generatePaths } from 'utils'; import { hasOnlyStaticVariables, variableName } from 'utils/variable'; import { scanForReferences } from 'utils/msgs'; +import { Template } from 'types'; interface TemplateNewInput { name: string; @@ -20,7 +21,7 @@ export interface TemplateNewState extends TemplateNewInput, FormState; -export const templateToInput = (template?: warp_templates.Template): TemplateNewInput => { +export const templateToInput = (template?: Template): TemplateNewInput => { return { name: template?.name ?? '', vars: template?.vars ?? [], @@ -30,7 +31,7 @@ export const templateToInput = (template?: warp_templates.Template): TemplateNew }; }; -export const useTemplateNewForm = (template?: warp_templates.Template) => { +export const useTemplateNewForm = (template?: Template) => { const initialValue = useMemo(() => { const res = { ...templateToInput(template), diff --git a/apps/warp-protocol/src/pages/templates/TemplateCard.tsx b/apps/warp-protocol/src/pages/templates/TemplateCard.tsx index 8720fb6e..c5f0c427 100644 --- a/apps/warp-protocol/src/pages/templates/TemplateCard.tsx +++ b/apps/warp-protocol/src/pages/templates/TemplateCard.tsx @@ -4,7 +4,6 @@ import { Text } from 'components/primitives'; import styles from './TemplateCard.module.sass'; import { Panel } from 'components/panel'; import MoreVertIcon from '@mui/icons-material/MoreVert'; -import { warp_templates } from '@terra-money/warp-sdk'; import { useDeleteTemplateTx } from 'tx'; import { MenuAction } from 'components/menu-button/MenuAction'; import { DropdownMenu } from 'components/dropdown-menu/DropdownMenu'; @@ -15,9 +14,10 @@ import { useLocalWallet } from '@terra-money/apps/hooks'; import { useEditTemplateDialog } from './edit-template'; import { useCopy } from 'hooks'; import { ActionButton } from 'components/action-button/ActionButton'; +import { Template } from 'types'; interface TemplateCardProps extends UIElementProps { - template: warp_templates.Template; + template: Template; } type FormattedDisplayProps = UIElementProps & { diff --git a/apps/warp-protocol/src/pages/templates/edit-template/EditTemplateDialog.tsx b/apps/warp-protocol/src/pages/templates/edit-template/EditTemplateDialog.tsx index fa9b8022..37e352bf 100644 --- a/apps/warp-protocol/src/pages/templates/edit-template/EditTemplateDialog.tsx +++ b/apps/warp-protocol/src/pages/templates/edit-template/EditTemplateDialog.tsx @@ -8,11 +8,11 @@ import { FormControl } from 'components/form-control/FormControl'; import { Form } from 'components/form/Form'; import { Dialog, DialogBody, DialogFooter, DialogHeader } from 'components/dialog'; import { useEditTemplateTx } from 'tx'; -import { warp_templates } from '@terra-money/warp-sdk'; import { useEditTemplateForm } from './useEditTemplateForm'; +import { Template } from 'types'; export type EditTemplateDialogProps = { - template: warp_templates.Template; + template: Template; }; export const EditTemplateDialog = (props: DialogProps) => { diff --git a/apps/warp-protocol/src/pages/templates/edit-template/useEditTemplateForm.ts b/apps/warp-protocol/src/pages/templates/edit-template/useEditTemplateForm.ts index ea183e8e..1a682521 100644 --- a/apps/warp-protocol/src/pages/templates/edit-template/useEditTemplateForm.ts +++ b/apps/warp-protocol/src/pages/templates/edit-template/useEditTemplateForm.ts @@ -1,6 +1,6 @@ import { FormFunction, FormState, useForm } from '@terra-money/apps/hooks'; import { useMemo } from 'react'; -import { warp_templates } from '@terra-money/warp-sdk'; +import { Template } from 'types'; export interface EditTemplateInput { name: string; @@ -10,7 +10,7 @@ export interface EditTemplateState extends FormState { submitDisabled: boolean; } -export const useEditTemplateForm = (template: warp_templates.Template) => { +export const useEditTemplateForm = (template: Template) => { const initialValue = useMemo( () => ({ name: template.name, diff --git a/apps/warp-protocol/src/queries/useTemplatesQuery.ts b/apps/warp-protocol/src/queries/useTemplatesQuery.ts index ec9adf53..32d9eb8f 100644 --- a/apps/warp-protocol/src/queries/useTemplatesQuery.ts +++ b/apps/warp-protocol/src/queries/useTemplatesQuery.ts @@ -3,14 +3,13 @@ import { useQuery, UseQueryResult } from 'react-query'; import { QUERY_KEY } from './queryKey'; import { useWarpSdk } from '@terra-money/apps/hooks'; import { warp_templates } from '@terra-money/warp-sdk'; +import { Template } from 'types'; type TemplatesQueryOpts = warp_templates.QueryTemplatesMsg & { enabled?: boolean; }; -export const useTemplatesQuery = ( - opts: TemplatesQueryOpts = {} -): UseQueryResult => { +export const useTemplatesQuery = (opts: TemplatesQueryOpts = {}): UseQueryResult => { const enabled = opts.enabled ?? true; const wallet = useLocalWallet(); const sdk = useWarpSdk(); @@ -20,7 +19,7 @@ export const useTemplatesQuery = ( async () => { const templates = await sdk.templates(opts); - return templates; + return templates.map((t) => new Template(t)); }, { refetchOnMount: false, @@ -29,5 +28,5 @@ export const useTemplatesQuery = ( } ); - return query as UseQueryResult; + return query as UseQueryResult; }; diff --git a/apps/warp-protocol/src/types/index.ts b/apps/warp-protocol/src/types/index.ts index c046f7f5..86406e2b 100644 --- a/apps/warp-protocol/src/types/index.ts +++ b/apps/warp-protocol/src/types/index.ts @@ -1,2 +1,3 @@ export * from './job'; export * from './tx'; +export * from './template'; diff --git a/apps/warp-protocol/src/types/template.ts b/apps/warp-protocol/src/types/template.ts new file mode 100644 index 00000000..a0b562d7 --- /dev/null +++ b/apps/warp-protocol/src/types/template.ts @@ -0,0 +1,26 @@ +import { warp_resolver } from '@terra-money/warp-sdk'; +import { warp_templates } from '@terra-money/warp-sdk'; + +export class Template { + // executions: Execution[]; + info: warp_templates.Template; + condition: warp_resolver.Condition; + msg: string; + formatted_str: string; + id: string; + name: string; + owner: string; + vars: warp_templates.Variable[]; + + constructor(info: warp_templates.Template) { + this.info = info; + this.condition = JSON.parse(info.executions[0].condition); + this.msg = info.executions[0].msgs; + this.vars = info.vars; + this.formatted_str = info.formatted_str; + this.id = info.id; + this.name = info.name; + this.owner = info.owner; + this.vars = info.vars; + } +} diff --git a/apps/warp-protocol/src/utils/variable.ts b/apps/warp-protocol/src/utils/variable.ts index 05f7c44a..e7700d16 100644 --- a/apps/warp-protocol/src/utils/variable.ts +++ b/apps/warp-protocol/src/utils/variable.ts @@ -1,4 +1,5 @@ -import { warp_resolver, warp_templates, extractVariableName } from '@terra-money/warp-sdk'; +import { warp_resolver, extractVariableName } from '@terra-money/warp-sdk'; +import { Template } from 'types'; export const resolveVariableRef = (ref: string, vars: warp_resolver.Variable[]) => { const name = extractVariableName(ref); @@ -52,7 +53,7 @@ export const variableKind = (v: warp_resolver.Variable): warp_resolver.VariableK return v.query.kind; }; -export const templateVariables = (template: warp_templates.Template) => { +export const templateVariables = (template: Template) => { const staticVariables = template.vars.filter((v) => 'static' in v) as Extract< warp_resolver.Variable, { static: {} } From 50c2ea17d2ac20bbf51ce4560ccc82ca90d778b5 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Mon, 11 Dec 2023 18:38:12 +0100 Subject: [PATCH 08/33] update editor input --- .../src/forms/QueryExprForm/EditorInput.tsx | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/apps/warp-protocol/src/forms/QueryExprForm/EditorInput.tsx b/apps/warp-protocol/src/forms/QueryExprForm/EditorInput.tsx index 017e2693..d4f49676 100644 --- a/apps/warp-protocol/src/forms/QueryExprForm/EditorInput.tsx +++ b/apps/warp-protocol/src/forms/QueryExprForm/EditorInput.tsx @@ -15,7 +15,7 @@ import { variableName } from 'utils/variable'; import CustomJsonSyntaxMode from './CustomJsonSyntaxMode'; import { IAceEditor } from 'react-ace/lib/types'; import { warp_resolver } from '@terra-money/warp-sdk'; -import { useWarpSdk } from '@terra-money/apps/hooks'; +import { useLocalWallet } from '@terra-money/apps/hooks'; export interface EditorInputProps { className?: string; @@ -41,20 +41,19 @@ export interface EditorInputProps { onEditorCursorChange?: (editor: IAceEditor) => void; } -const defaultExample = (contractAddr: string): warp_resolver.CosmosMsgFor_Empty => ({ - wasm: { - execute: { - contract_addr: contractAddr, - msg: 'eyJ0ZXN0X21zZyI6eyJpZCI6IjEyMyJ9fQ==', - funds: [], +const defaultExample = (walletAddr: string): warp_resolver.WarpMsg => ({ + generic: { + bank: { + send: { + amount: [{ amount: '1000000', denom: 'uluna' }], + to_address: walletAddr, + }, }, }, }); const EditorInput = (props: EditorInputProps) => { - const sdk = useWarpSdk(); - - const contractAddr = sdk.chain.contracts.controller; + const { walletAddress } = useLocalWallet(); const { endLabel, @@ -68,7 +67,7 @@ const EditorInput = (props: EditorInputProps) => { mode = 'json', onChange, readOnly, - example = defaultExample(contractAddr), + example = defaultExample(walletAddress), onEditorCursorChange, suggestItems, } = props; From 35788274a1bd49da5b69ac4f912aad6907455ff7 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Tue, 12 Dec 2023 23:15:08 +0100 Subject: [PATCH 09/33] minor --- apps/warp-protocol/src/pages/balances/BalanceCard.tsx | 4 ++-- apps/warp-protocol/src/queries/useWarpAccount.ts | 4 ++-- apps/warp-protocol/src/tx/useAddFundsTx.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/warp-protocol/src/pages/balances/BalanceCard.tsx b/apps/warp-protocol/src/pages/balances/BalanceCard.tsx index 6410a5f9..a57622a5 100644 --- a/apps/warp-protocol/src/pages/balances/BalanceCard.tsx +++ b/apps/warp-protocol/src/pages/balances/BalanceCard.tsx @@ -26,11 +26,11 @@ export const BalanceCard = (props: BalanceCardProps) => { balance ); - const { data: warpAccount = { addr: walletAddr }, isLoading: isWarpAccountLoading } = useWarpAccount(); + const { data: warpAccount = { account_addr: walletAddr }, isLoading: isWarpAccountLoading } = useWarpAccount(); // TODO: implement const { data: warpBalance = Big(0) as u, isLoading: isWarpBalanceLoading } = useTokenBalanceQuery( - warpAccount.addr, + warpAccount.account_addr, balance ); diff --git a/apps/warp-protocol/src/queries/useWarpAccount.ts b/apps/warp-protocol/src/queries/useWarpAccount.ts index bcc1df1b..690f6660 100644 --- a/apps/warp-protocol/src/queries/useWarpAccount.ts +++ b/apps/warp-protocol/src/queries/useWarpAccount.ts @@ -3,7 +3,7 @@ import { useQuery, UseQueryResult } from 'react-query'; import { warp_account_tracker } from '@terra-money/warp-sdk'; import { QUERY_KEY } from './queryKey'; -export const useWarpAccount = (): UseQueryResult => { +export const useWarpAccount = (): UseQueryResult => { const { connectedWallet, chainId } = useLocalWallet(); const query = useQuery( @@ -25,5 +25,5 @@ export const useWarpAccount = (): UseQueryResult; + return query as UseQueryResult; }; diff --git a/apps/warp-protocol/src/tx/useAddFundsTx.ts b/apps/warp-protocol/src/tx/useAddFundsTx.ts index 6393e5d4..c417b587 100644 --- a/apps/warp-protocol/src/tx/useAddFundsTx.ts +++ b/apps/warp-protocol/src/tx/useAddFundsTx.ts @@ -13,7 +13,7 @@ interface AddFundsTxProps { } export const useAddFundsTx = () => { - const { data: account = {} as warp_account_tracker.Account } = useWarpAccount(); + const { data: account = {} as warp_account_tracker.FundingAccount } = useWarpAccount(); const sdk = useWarpSdk(); return useTx( @@ -22,7 +22,7 @@ export const useAddFundsTx = () => { // TODO: implement - return sdk.tx.depositToAccount(account.addr, account.addr, token, amount.toString()); + return sdk.tx.depositToAccount(account.account_addr, account.account_addr, token, amount.toString()); }, { txKey: TX_KEY.ADD_FUNDS, From ac66e9de59dee44e01d4446678fd735966fd2dfc Mon Sep 17 00:00:00 2001 From: simke9445 Date: Wed, 20 Dec 2023 21:18:41 +0100 Subject: [PATCH 10/33] add funding accounts query --- .../dashboard/jobs-widget/JobsWidget.tsx | 2 +- apps/warp-protocol/src/queries/index.ts | 1 + apps/warp-protocol/src/queries/queryKey.ts | 1 + .../src/queries/useFundingAccountsQuery.ts | 33 +++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 apps/warp-protocol/src/queries/useFundingAccountsQuery.ts diff --git a/apps/warp-protocol/src/pages/dashboard/jobs-widget/JobsWidget.tsx b/apps/warp-protocol/src/pages/dashboard/jobs-widget/JobsWidget.tsx index 7748c88b..3a582b91 100644 --- a/apps/warp-protocol/src/pages/dashboard/jobs-widget/JobsWidget.tsx +++ b/apps/warp-protocol/src/pages/dashboard/jobs-widget/JobsWidget.tsx @@ -25,7 +25,7 @@ type PageIndexMap = { }; export const JobsWidget = (props: JobsWidgetProps) => { - const { className, limit = 20, showExpand } = props; + const { className, limit = 10, showExpand } = props; const [sort, setSort] = useState>(); const [queryOpts, setQueryOpts] = useState({ job_status: 'Pending' }); diff --git a/apps/warp-protocol/src/queries/index.ts b/apps/warp-protocol/src/queries/index.ts index 01fab5a1..45a34513 100644 --- a/apps/warp-protocol/src/queries/index.ts +++ b/apps/warp-protocol/src/queries/index.ts @@ -5,3 +5,4 @@ export * from './useAnalyticsQuery'; export * from './useJobsQuery'; export * from './useTemplateQuery'; export * from './useTemplatesQuery'; +export * from './useFundingAccountsQuery'; diff --git a/apps/warp-protocol/src/queries/queryKey.ts b/apps/warp-protocol/src/queries/queryKey.ts index ad826ec9..a4914154 100644 --- a/apps/warp-protocol/src/queries/queryKey.ts +++ b/apps/warp-protocol/src/queries/queryKey.ts @@ -14,4 +14,5 @@ export enum QUERY_KEY { BLOCK_HEIGHT = 'QUERY:BLOCK_HEIGHT', TEMPLATES = 'QUERY:TEMPLATES', TEMPLATE = 'QUERY:TEMPLATE', + FUNDING_ACCOUNTS = 'FUNDING_ACCOUNTS', } diff --git a/apps/warp-protocol/src/queries/useFundingAccountsQuery.ts b/apps/warp-protocol/src/queries/useFundingAccountsQuery.ts new file mode 100644 index 00000000..0b4fac51 --- /dev/null +++ b/apps/warp-protocol/src/queries/useFundingAccountsQuery.ts @@ -0,0 +1,33 @@ +import { useLocalWallet } from '@terra-money/apps/hooks'; +import { useQuery, UseQueryResult } from 'react-query'; +import { QUERY_KEY } from './queryKey'; +import { useWarpSdk } from '@terra-money/apps/hooks'; +import { warp_account_tracker } from '@terra-money/warp-sdk'; + +type FundingAccountsQueryOpts = warp_account_tracker.QueryFundingAccountsMsg & { + enabled?: boolean; +}; + +export const useFundingAccountsQuery = ( + opts: FundingAccountsQueryOpts +): UseQueryResult => { + const enabled = opts.enabled ?? true; + const wallet = useLocalWallet(); + const sdk = useWarpSdk(); + + const query = useQuery( + [QUERY_KEY.FUNDING_ACCOUNTS, wallet.chainId, JSON.stringify(opts)], + async () => { + const response = await sdk.fundingAccounts(opts); + + return response.funding_accounts; + }, + { + refetchOnMount: false, + keepPreviousData: false, + enabled, + } + ); + + return query as UseQueryResult; +}; From 306dd01e40e34f55e845b38143bb5c120d68f17e Mon Sep 17 00:00:00 2001 From: simke9445 Date: Wed, 20 Dec 2023 21:20:08 +0100 Subject: [PATCH 11/33] add create funding account tx --- apps/warp-protocol/src/tx/txKey.ts | 1 + .../src/tx/useCreateFundingAccountTx.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 apps/warp-protocol/src/tx/useCreateFundingAccountTx.ts diff --git a/apps/warp-protocol/src/tx/txKey.ts b/apps/warp-protocol/src/tx/txKey.ts index 2f647c6a..c83d5ef2 100644 --- a/apps/warp-protocol/src/tx/txKey.ts +++ b/apps/warp-protocol/src/tx/txKey.ts @@ -10,4 +10,5 @@ export enum TX_KEY { CREATE_TEMPLATE = 'TX:CREATE_TEMPLATE', EDIT_TEMPLATE = 'TX:EDIT_TEMPLATE', DELETE_TEMPLATE = 'TX:DELETE_TEMPLATE', + CREATE_FUNDING_ACCOUNT = 'TX:CREATE_FUNDING_ACCOUNT', } diff --git a/apps/warp-protocol/src/tx/useCreateFundingAccountTx.ts b/apps/warp-protocol/src/tx/useCreateFundingAccountTx.ts new file mode 100644 index 00000000..489fc89f --- /dev/null +++ b/apps/warp-protocol/src/tx/useCreateFundingAccountTx.ts @@ -0,0 +1,20 @@ +import { useTx } from '@terra-money/apps/libs/transactions'; +import { TX_KEY } from './txKey'; +import { useWarpSdk } from '@terra-money/apps/hooks'; + +interface CreateFundingAccountTxProps {} + +export const useCreateFundingAccountTx = () => { + const sdk = useWarpSdk(); + + return useTx( + async (options) => { + const { wallet } = options; + + return sdk.tx.createFundingAccount(wallet.walletAddress); + }, + { + txKey: TX_KEY.CREATE_FUNDING_ACCOUNT, + } + ); +}; From d46149f0b5dac692ec1902879feb995ae9dfce38 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Wed, 20 Dec 2023 21:21:04 +0100 Subject: [PATCH 12/33] fix --- apps/warp-protocol/src/hooks/useTransactionSnackbars.tsx | 2 ++ apps/warp-protocol/src/queries/useRefetchQueries.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/apps/warp-protocol/src/hooks/useTransactionSnackbars.tsx b/apps/warp-protocol/src/hooks/useTransactionSnackbars.tsx index a59a15df..86f31340 100644 --- a/apps/warp-protocol/src/hooks/useTransactionSnackbars.tsx +++ b/apps/warp-protocol/src/hooks/useTransactionSnackbars.tsx @@ -25,6 +25,7 @@ const CompletedSnackbarMessages: TxMessages = { [TX_KEY.CREATE_TEMPLATE]: 'Template created successfully', [TX_KEY.EDIT_TEMPLATE]: 'Template edited successfully', [TX_KEY.DELETE_TEMPLATE]: 'Template deleted successfully', + [TX_KEY.CREATE_FUNDING_ACCOUNT]: 'Funding account created successfully', }; const FailedSnackbarMessages: TxMessages = { @@ -38,6 +39,7 @@ const FailedSnackbarMessages: TxMessages = { [TX_KEY.CREATE_TEMPLATE]: 'Failed to create template', [TX_KEY.EDIT_TEMPLATE]: 'Failed to edit template', [TX_KEY.DELETE_TEMPLATE]: 'Failed to delete template', + [TX_KEY.CREATE_FUNDING_ACCOUNT]: 'Failed to create funding account', }; export const useTransactionSnackbars = () => { diff --git a/apps/warp-protocol/src/queries/useRefetchQueries.ts b/apps/warp-protocol/src/queries/useRefetchQueries.ts index 61b5e540..85aebd6a 100644 --- a/apps/warp-protocol/src/queries/useRefetchQueries.ts +++ b/apps/warp-protocol/src/queries/useRefetchQueries.ts @@ -22,6 +22,7 @@ const QUERY_REFETCH_MAP: QueryRefetchMap = { [TX_KEY.CREATE_TEMPLATE]: [QUERY_KEY.TEMPLATES], [TX_KEY.EDIT_TEMPLATE]: [QUERY_KEY.TEMPLATES], [TX_KEY.DELETE_TEMPLATE]: [QUERY_KEY.TEMPLATES], + [TX_KEY.CREATE_FUNDING_ACCOUNT]: [QUERY_KEY.FUNDING_ACCOUNTS], }; const runRefetch = (queryRefetch: string | QueryRefetch): Promise => { From 46a591de4c4829d53ff3305d1f8a10c915ae7eb9 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Wed, 20 Dec 2023 22:01:07 +0100 Subject: [PATCH 13/33] add funding accounts UI - wip --- apps/warp-protocol/src/App.tsx | 6 +- .../src/components/layout/NavigationMenu.tsx | 2 +- .../src/pages/balances/Balances.tsx | 16 ++--- .../src/pages/balances/BalancesPage.tsx | 9 ++- .../src/pages/balances/useBalances.ts | 26 +++---- .../src/pages/funding-accounts/EmptyView.tsx | 25 +++++++ .../FundingAccountCard.module.sass | 64 +++++++++++++++++ .../funding-accounts/FundingAccountCard.tsx | 32 +++++++++ .../FundingAccounts.module.sass | 61 ++++++++++++++++ .../funding-accounts/FundingAccounts.tsx | 71 +++++++++++++++++++ .../src/pages/funding-accounts/index.ts | 1 + apps/warp-protocol/src/tx/index.ts | 1 + 12 files changed, 277 insertions(+), 37 deletions(-) create mode 100644 apps/warp-protocol/src/pages/funding-accounts/EmptyView.tsx create mode 100644 apps/warp-protocol/src/pages/funding-accounts/FundingAccountCard.module.sass create mode 100644 apps/warp-protocol/src/pages/funding-accounts/FundingAccountCard.tsx create mode 100644 apps/warp-protocol/src/pages/funding-accounts/FundingAccounts.module.sass create mode 100644 apps/warp-protocol/src/pages/funding-accounts/FundingAccounts.tsx create mode 100644 apps/warp-protocol/src/pages/funding-accounts/index.ts diff --git a/apps/warp-protocol/src/App.tsx b/apps/warp-protocol/src/App.tsx index 5f2a1520..ecb39be2 100644 --- a/apps/warp-protocol/src/App.tsx +++ b/apps/warp-protocol/src/App.tsx @@ -14,12 +14,13 @@ import { Dashboard } from 'pages/dashboard/Dashboard'; import { Jobs } from 'pages/jobs/Jobs'; import { JobPage } from 'pages/job-page/JobPage'; import { JobNew } from 'pages/job-new/JobNew'; -import { BalancesPage } from 'pages/balances'; import { Variables } from 'pages/variables/Variables'; import { TemplateNew } from 'pages/template-new/TemplateNew'; import { TemplatesPage } from 'pages/templates'; import { useWalletDefaultNetworks } from 'hooks/useWalletDefaultNetworks'; import { ChainSelectorProvider } from '@terra-money/apps/hooks'; +import { BalancesPage } from 'pages/balances'; +import { FundingAccounts } from 'pages/funding-accounts'; const queryClient = new QueryClient(); @@ -31,7 +32,8 @@ const Main = () => { } /> } /> - } /> + } /> + } /> } /> } /> } /> diff --git a/apps/warp-protocol/src/components/layout/NavigationMenu.tsx b/apps/warp-protocol/src/components/layout/NavigationMenu.tsx index 131e932f..ab1d2f7f 100644 --- a/apps/warp-protocol/src/components/layout/NavigationMenu.tsx +++ b/apps/warp-protocol/src/components/layout/NavigationMenu.tsx @@ -20,7 +20,7 @@ interface RouteProps { const routes: RouteProps[] = [ { to: '/dashboard', label: 'Dashboard', icon: }, { to: '/jobs', label: 'Jobs', icon: }, - { to: '/balances', label: 'Balances', icon: }, + { to: '/funding-accounts', label: 'Funding Accounts', icon: }, { to: '/variables', label: 'Variables', icon: }, { to: '/templates', label: 'Templates', icon: }, ]; diff --git a/apps/warp-protocol/src/pages/balances/Balances.tsx b/apps/warp-protocol/src/pages/balances/Balances.tsx index 4cdb8f2e..5124cbd3 100644 --- a/apps/warp-protocol/src/pages/balances/Balances.tsx +++ b/apps/warp-protocol/src/pages/balances/Balances.tsx @@ -4,16 +4,15 @@ import { BalanceCard } from './BalanceCard'; import styles from './Balances.module.sass'; import { useBalances } from './useBalances'; import { useTokenListDialog } from './token-list'; -import { LocalWallet } from '@terra-money/apps/hooks'; interface BalancesProps { - connectedWallet: LocalWallet; + walletAddress: string; } export const Balances = (props: BalancesProps) => { - const { connectedWallet } = props; + const { walletAddress } = props; - const { balances, saveAll } = useBalances(); + const { balances, saveAll } = useBalances(walletAddress); const openTokenListDialog = useTokenListDialog(); @@ -38,14 +37,7 @@ export const Balances = (props: BalancesProps) => { {balances.map((balance) => { - return ( - - ); + return ; })} diff --git a/apps/warp-protocol/src/pages/balances/BalancesPage.tsx b/apps/warp-protocol/src/pages/balances/BalancesPage.tsx index fe208d1f..de115bb2 100644 --- a/apps/warp-protocol/src/pages/balances/BalancesPage.tsx +++ b/apps/warp-protocol/src/pages/balances/BalancesPage.tsx @@ -1,9 +1,8 @@ -import { IfConnected } from 'components/if-connected'; -import { NotConnected } from 'components/not-connected'; +import { useParams } from 'react-router'; import { Balances } from './Balances'; export const BalancesPage = () => { - return ( - } else={} /> - ); + const { fundingAccountAddress } = useParams(); + + return ; }; diff --git a/apps/warp-protocol/src/pages/balances/useBalances.ts b/apps/warp-protocol/src/pages/balances/useBalances.ts index d5f5f3a7..b3892306 100644 --- a/apps/warp-protocol/src/pages/balances/useBalances.ts +++ b/apps/warp-protocol/src/pages/balances/useBalances.ts @@ -1,4 +1,4 @@ -import { LocalWallet, useChainSuffix, useLocalWallet } from '@terra-money/apps/hooks'; +import { useChainSelector, useChainSuffix } from '@terra-money/apps/hooks'; import { useNativeToken } from 'hooks/useNativeToken'; import { useCallback, useMemo } from 'react'; import { Token } from '@terra-money/apps/types'; @@ -8,40 +8,32 @@ type BalancesStorage = { [key: string]: Token[]; }; -const storageKey = (connectedWallet: LocalWallet) => `${connectedWallet.chainId}--${connectedWallet.walletAddress}`; +const storageKey = (chainId: string, walletAddress: string) => `${chainId}--${walletAddress}`; -export const useBalances = () => { - const localWallet = useLocalWallet(); +export const useBalances = (walletAddress: string) => { + const { selectedChainId } = useChainSelector(); const nativeToken = useNativeToken(); const defaultTokens = useMemo(() => [nativeToken], [nativeToken]); - const storedBalancesKey = useChainSuffix('__warp_stored_balances'); + const storedBalancesKey = useChainSuffix('__warp_stored_funding_account_balances'); const [storedBalances, setStoredBalances] = useLocalStorage(storedBalancesKey, {}); const setBalances = useCallback( (tokens: Token[]) => { - if (!localWallet.connectedWallet) { - return; - } - setStoredBalances((storedBalances) => { return { ...storedBalances, - [storageKey(localWallet)]: tokens, + [storageKey(selectedChainId, walletAddress)]: tokens, }; }); }, - [localWallet, setStoredBalances] + [walletAddress, setStoredBalances, selectedChainId] ); const balances = useMemo(() => { - if (!localWallet.connectedWallet) { - return []; - } - - return storedBalances[storageKey(localWallet)] ?? defaultTokens; - }, [storedBalances, localWallet, defaultTokens]); + return storedBalances[storageKey(selectedChainId, walletAddress)] ?? defaultTokens; + }, [storedBalances, walletAddress, selectedChainId, defaultTokens]); const saveAll = useCallback( (tokens: Token[]) => { diff --git a/apps/warp-protocol/src/pages/funding-accounts/EmptyView.tsx b/apps/warp-protocol/src/pages/funding-accounts/EmptyView.tsx new file mode 100644 index 00000000..9f58c72b --- /dev/null +++ b/apps/warp-protocol/src/pages/funding-accounts/EmptyView.tsx @@ -0,0 +1,25 @@ +import { Text } from 'components/primitives'; + +import styles from './FundingAccounts.module.sass'; +import { ActionButton } from 'components/action-button/ActionButton'; +import { Container } from '@terra-money/apps/components'; +import { useCreateFundingAccountTx } from 'tx'; + +export const EmptyView = () => { + const [txResult, createFundingAccountTx] = useCreateFundingAccountTx(); + + return ( + + Nothing to display. Results will appear after a funding account is created. + createFundingAccountTx({})} + > + New funding account + + + ); +}; diff --git a/apps/warp-protocol/src/pages/funding-accounts/FundingAccountCard.module.sass b/apps/warp-protocol/src/pages/funding-accounts/FundingAccountCard.module.sass new file mode 100644 index 00000000..0fb883a3 --- /dev/null +++ b/apps/warp-protocol/src/pages/funding-accounts/FundingAccountCard.module.sass @@ -0,0 +1,64 @@ +.root + padding: 20px + display: flex + flex-direction: column + min-height: 160px + +.buttons + display: grid + grid-template-columns: 1fr 1fr + column-gap: 16px !important + +.pill + font-size: 12px + border-radius: 20px + padding: 4px 12px + margin-left: auto + +.menu_btn + min-height: 0 !important + min-width: 0 !important + height: auto !important + width: 20px + margin: 0 + margin-top: 2px !important + margin-left: 12px !important + cursor: pointer + + path + fill: rgba(223, 226, 225, 0.4) !important + +.name + margin-bottom: 8px + +.menu + width: 140px + margin-top: -20px + +.top + width: 100% + + .left + margin-right: auto + + .right + margin-bottom: auto + +.bottom + margin-top: auto + +.highlighted + position: relative + color: #a9fc50 + +.highlighted:after + content: '' + position: absolute + border-radius: 20px + background: rgba(47, 51, 57, 0.6) + z-index: -1 + top: -2px + left: -4px + bottom: -2px + right: -4px + height: calc(100% + 4px) diff --git a/apps/warp-protocol/src/pages/funding-accounts/FundingAccountCard.tsx b/apps/warp-protocol/src/pages/funding-accounts/FundingAccountCard.tsx new file mode 100644 index 00000000..5c8568b9 --- /dev/null +++ b/apps/warp-protocol/src/pages/funding-accounts/FundingAccountCard.tsx @@ -0,0 +1,32 @@ +import { Container, UIElementProps } from '@terra-money/apps/components'; +import classNames from 'classnames'; +import { Text } from 'components/primitives'; +import styles from './FundingAccountCard.module.sass'; +import { Panel } from 'components/panel'; +import { warp_account_tracker } from '@terra-money/warp-sdk'; +import { useNavigate } from 'react-router'; + +interface FundingAccountCardProps extends UIElementProps { + fundingAccount: warp_account_tracker.FundingAccount; +} + +export const FundingAccountCard = (props: FundingAccountCardProps) => { + const { className, fundingAccount } = props; + + const navigate = useNavigate(); + + return ( + + navigate(`/funding-accounts/${fundingAccount.account_addr}`)}> + + + {fundingAccount.account_addr} + + + + + TODO + + + ); +}; diff --git a/apps/warp-protocol/src/pages/funding-accounts/FundingAccounts.module.sass b/apps/warp-protocol/src/pages/funding-accounts/FundingAccounts.module.sass new file mode 100644 index 00000000..d5bac23d --- /dev/null +++ b/apps/warp-protocol/src/pages/funding-accounts/FundingAccounts.module.sass @@ -0,0 +1,61 @@ +.root + display: flex + flex-direction: column + height: 100% + +.empty + color: var(--text-color-primary) + height: 100% + justify-content: center + align-items: center + display: flex + +.container + display: flex + flex-direction: column + height: 100% + justify-content: center + align-items: center + +.throbber + flex-grow: 1 + margin-left: auto + margin-right: auto + +.title + font-weight: 600 + font-size: 40px + margin-bottom: 40px + +.header + margin-bottom: 40px + display: flex + padding-right: 16px + margin-bottom: 32px + justify-content: space-between + +.fundingAccounts + display: grid + grid-template-columns: 1fr 1fr + column-gap: 16px !important + row-gap: 16px !important + padding-bottom: 32px + overflow: auto + padding-right: 16px + +.new_icon + margin-right: 8px + +.top + width: 100% + +.tabs + margin-right: auto + +.tab + border-radius: 16px + text-transform: capitalize + margin-right: 12px + + &:not(.selected_tab) + opacity: 0.4 diff --git a/apps/warp-protocol/src/pages/funding-accounts/FundingAccounts.tsx b/apps/warp-protocol/src/pages/funding-accounts/FundingAccounts.tsx new file mode 100644 index 00000000..e73e4e11 --- /dev/null +++ b/apps/warp-protocol/src/pages/funding-accounts/FundingAccounts.tsx @@ -0,0 +1,71 @@ +import { Button, Text, Throbber } from 'components/primitives'; +import { Container } from '@terra-money/apps/components'; +import { ReactComponent as PlusIcon } from 'components/assets/Plus.svg'; +import styles from './FundingAccounts.module.sass'; +import { ActionButton } from 'components/action-button/ActionButton'; +import { FundingAccountCard } from './FundingAccountCard'; +import { EmptyView } from './EmptyView'; +import { useFundingAccountsQuery } from 'queries'; +import { useCreateFundingAccountTx } from 'tx'; +import { warp_account_tracker } from '@terra-money/warp-sdk'; +import { useState } from 'react'; +import { useLocalWallet } from '@terra-money/apps/hooks'; +import classNames from 'classnames'; + +interface FundingAccountsProps {} + +const accountStatuses = ['free', 'taken'] as warp_account_tracker.AccountStatus[]; + +export const FundingAccounts = (props: FundingAccountsProps) => { + const [selectedAccountStatus, setSelectedAccountStatus] = useState('taken'); + + const { walletAddress } = useLocalWallet(); + + const { data: fundingAccounts = [], isLoading } = useFundingAccountsQuery({ + account_owner_addr: walletAddress, + account_status: selectedAccountStatus, + }); + + const [txResult, createFundingAccountTx] = useCreateFundingAccountTx(); + + return ( + + + + FundingAccounts + + + + {accountStatuses.map((curr) => ( + + ))} + + } + iconGap="none" + variant="primary" + loading={txResult.loading} + onClick={() => createFundingAccountTx({})} + > + New + + + + {isLoading && fundingAccounts.length === 0 && } + + {fundingAccounts.map((acc) => { + return ; + })} + + {!isLoading && fundingAccounts.length === 0 && } + + ); +}; diff --git a/apps/warp-protocol/src/pages/funding-accounts/index.ts b/apps/warp-protocol/src/pages/funding-accounts/index.ts new file mode 100644 index 00000000..7de319da --- /dev/null +++ b/apps/warp-protocol/src/pages/funding-accounts/index.ts @@ -0,0 +1 @@ +export * from './FundingAccounts'; diff --git a/apps/warp-protocol/src/tx/index.ts b/apps/warp-protocol/src/tx/index.ts index 62bec3f6..b34e693e 100644 --- a/apps/warp-protocol/src/tx/index.ts +++ b/apps/warp-protocol/src/tx/index.ts @@ -8,3 +8,4 @@ export * from './useCreateTemplateTx'; export * from './useDeleteTemplateTx'; export * from './useEditTemplateTx'; export * from './useCreateDevJobTx'; +export * from './useCreateFundingAccountTx'; From 1e34152576050bea9375fd60efe857f7f7d64998 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Tue, 9 Jan 2024 14:16:35 +0100 Subject: [PATCH 14/33] finish balances per funding account logic --- .../src/components/panel/Panel.tsx | 5 ++-- .../src/pages/balances/AddFundsDialog.tsx | 5 ++-- .../src/pages/balances/BalanceCard.tsx | 19 ++++++------ .../src/pages/balances/Balances.module.sass | 7 +++++ .../src/pages/balances/Balances.tsx | 18 +++++++++--- .../src/pages/balances/BalancesPage.tsx | 2 +- .../pages/balances/WithdrawFundsDialog.tsx | 5 ++-- .../dashboard/jobs-widget/columns/action.tsx | 5 +--- .../FundingAccountCard.module.sass | 1 + .../funding-accounts/FundingAccountCard.tsx | 7 +++-- .../funding-accounts/FundingAccounts.tsx | 2 +- .../src/queries/useRefetchQueries.ts | 2 +- .../src/queries/useWarpAccount.ts | 29 ------------------- apps/warp-protocol/src/tx/useAddFundsTx.ts | 11 ++----- .../src/tx/useWithdrawFundsTx.ts | 5 ++-- 15 files changed, 55 insertions(+), 68 deletions(-) delete mode 100644 apps/warp-protocol/src/queries/useWarpAccount.ts diff --git a/apps/warp-protocol/src/components/panel/Panel.tsx b/apps/warp-protocol/src/components/panel/Panel.tsx index 8aa17b9e..ea9d5a7f 100644 --- a/apps/warp-protocol/src/components/panel/Panel.tsx +++ b/apps/warp-protocol/src/components/panel/Panel.tsx @@ -7,13 +7,14 @@ interface PanelProps extends UIElementProps { title?: string; isLoading?: boolean; ThrobberProps?: UIElementProps & {}; + onClick?: () => void; } export const Panel = (props: PanelProps) => { - const { ThrobberProps, className, title, children, isLoading } = props; + const { ThrobberProps, className, title, children, isLoading, onClick } = props; return ( - + {title && ( {title} diff --git a/apps/warp-protocol/src/pages/balances/AddFundsDialog.tsx b/apps/warp-protocol/src/pages/balances/AddFundsDialog.tsx index 38abd179..16732029 100644 --- a/apps/warp-protocol/src/pages/balances/AddFundsDialog.tsx +++ b/apps/warp-protocol/src/pages/balances/AddFundsDialog.tsx @@ -11,15 +11,16 @@ import { TokenInput } from './token-input/TokenInput'; interface AddFundsProps { token?: Token; + fundingAccountAddress: string; } const AddFundsDialog = (props: DialogProps) => { - const { token: selectedToken, closeDialog } = props; + const { token: selectedToken, closeDialog, fundingAccountAddress } = props; const [input, { token, balance, balanceLoading, amount, amountValid, amountError, submitDisabled }] = useAddFundsForm(selectedToken); - const [txResult, tx] = useAddFundsTx(); + const [txResult, tx] = useAddFundsTx(fundingAccountAddress); return ( diff --git a/apps/warp-protocol/src/pages/balances/BalanceCard.tsx b/apps/warp-protocol/src/pages/balances/BalanceCard.tsx index a57622a5..e4aae84a 100644 --- a/apps/warp-protocol/src/pages/balances/BalanceCard.tsx +++ b/apps/warp-protocol/src/pages/balances/BalanceCard.tsx @@ -8,29 +8,28 @@ import { Token, u } from '@terra-money/apps/types'; import { AnimatedTokenIcon } from './AnimatedTokenIcon'; import styles from './BalanceCard.module.sass'; import { useTokenBalanceQuery } from 'queries/useTokenBalanceQuery'; -import { useWarpAccount } from 'queries/useWarpAccount'; import { Panel } from 'components/panel'; import { TokenAmount } from 'components/token-amount'; +import { useLocalWallet } from '@terra-money/apps/hooks'; interface BalanceCardProps extends UIElementProps { balance: Token; - walletAddr: string; + fundingAccountAddress: string; displayAsFiat: boolean; } export const BalanceCard = (props: BalanceCardProps) => { - const { className, balance, walletAddr } = props; + const { className, balance, fundingAccountAddress } = props; + + const { walletAddress } = useLocalWallet(); const { data: walletBalance = Big(0) as u, isLoading: isWalletBalanceLoading } = useTokenBalanceQuery( - walletAddr, + walletAddress, balance ); - const { data: warpAccount = { account_addr: walletAddr }, isLoading: isWarpAccountLoading } = useWarpAccount(); - - // TODO: implement const { data: warpBalance = Big(0) as u, isLoading: isWarpBalanceLoading } = useTokenBalanceQuery( - warpAccount.account_addr, + fundingAccountAddress, balance ); @@ -48,7 +47,7 @@ export const BalanceCard = (props: BalanceCardProps) => { Account { onClick={() => openAddFundsDialog({ token: balance, + fundingAccountAddress, }) } > @@ -86,6 +86,7 @@ export const BalanceCard = (props: BalanceCardProps) => { openWithdrawFundsDialog({ token: balance, balance: warpBalance, + fundingAccountAddress, }) } > diff --git a/apps/warp-protocol/src/pages/balances/Balances.module.sass b/apps/warp-protocol/src/pages/balances/Balances.module.sass index 259099ca..aded2423 100644 --- a/apps/warp-protocol/src/pages/balances/Balances.module.sass +++ b/apps/warp-protocol/src/pages/balances/Balances.module.sass @@ -18,6 +18,13 @@ .title font-weight: 600 font-size: 40px + display: flex + flex-direction: column + align-items: start + +.wallet + font-weight: 400 + margin-top: 10px .header margin-bottom: 40px diff --git a/apps/warp-protocol/src/pages/balances/Balances.tsx b/apps/warp-protocol/src/pages/balances/Balances.tsx index 5124cbd3..400bea81 100644 --- a/apps/warp-protocol/src/pages/balances/Balances.tsx +++ b/apps/warp-protocol/src/pages/balances/Balances.tsx @@ -6,13 +6,13 @@ import { useBalances } from './useBalances'; import { useTokenListDialog } from './token-list'; interface BalancesProps { - walletAddress: string; + fundingAccountAddress: string; } export const Balances = (props: BalancesProps) => { - const { walletAddress } = props; + const { fundingAccountAddress } = props; - const { balances, saveAll } = useBalances(walletAddress); + const { balances, saveAll } = useBalances(fundingAccountAddress); const openTokenListDialog = useTokenListDialog(); @@ -21,6 +21,9 @@ export const Balances = (props: BalancesProps) => { Balances + + {fundingAccountAddress} + */} + + + + ); +}; From 2d59e068b562ca14743d175a929b94c07dfa9f39 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Wed, 17 Jan 2024 23:07:41 +0100 Subject: [PATCH 21/33] summary form --- .../job-new/condition-form/ConditionForm.tsx | 2 +- .../summary-form/SummaryForm.module.sass | 92 ++++++++++++++++++- .../job-new/summary-form/SummaryForm.tsx | 86 ++++++++++++----- 3 files changed, 153 insertions(+), 27 deletions(-) diff --git a/apps/warp-protocol/src/pages/job-new/condition-form/ConditionForm.tsx b/apps/warp-protocol/src/pages/job-new/condition-form/ConditionForm.tsx index d77b4b02..e05e7b8f 100644 --- a/apps/warp-protocol/src/pages/job-new/condition-form/ConditionForm.tsx +++ b/apps/warp-protocol/src/pages/job-new/condition-form/ConditionForm.tsx @@ -59,7 +59,7 @@ export const ConditionForm = (props: ConditionFormProps) => { } }} > - Save + Next + ))} + + + + + {`Displaying ${listData.fundingAccounts.length} ${pluralize( + 'funding accounts', + listData.fundingAccounts.length + )}`} + Balance + + {isLoading && } + {isLoading === false && ( + + className={styles.list} + itemData={listData} + height={300} + width={520} + itemSize={60} + itemCount={listData.fundingAccounts.length} + overscanCount={5} + > + {ListItem} + + )} + + + ); +}; + +export const useFundingAccountListDialog = () => { + return useDialog(FundingAccountListDialog); +}; diff --git a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListData.ts b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListData.ts new file mode 100644 index 00000000..69d3305f --- /dev/null +++ b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListData.ts @@ -0,0 +1,6 @@ +import { warp_account_tracker } from '@terra-money/warp-sdk'; + +export interface ListData { + fundingAccounts: warp_account_tracker.FundingAccount[]; + onSelectionChanged: (fundingAccount: warp_account_tracker.FundingAccount) => void; +} diff --git a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListItem.module.sass b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListItem.module.sass new file mode 100644 index 00000000..99d297f2 --- /dev/null +++ b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListItem.module.sass @@ -0,0 +1,26 @@ +.listItem + padding: 8px 32px + height: 60px + display: grid + grid-template-rows: 1fr 1fr + grid-template-columns: auto 1fr auto + align-items: center + &:hover + cursor: pointer + background-color: var(--list-item-hover) + .icon + width: 32px + height: 32px + grid-row: 1 / span 2 + grid-column: 1 + margin-right: 16px + .symbol + grid-row: 1 + grid-column: 2 + color: var(--text-color-title) + .name + grid-row: 2 + grid-column: 2 + .balance + grid-row: 1 / span 2 + grid-column: 3 diff --git a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListItem.tsx b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListItem.tsx new file mode 100644 index 00000000..91ee3d2b --- /dev/null +++ b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListItem.tsx @@ -0,0 +1,35 @@ +import { Text } from 'components/primitives'; +import { ListChildComponentProps } from 'react-window'; +import { TokenBalance } from './TokenBalance'; +import { ListData } from './ListData'; +import styles from './ListItem.module.sass'; +import { useTokenBalanceQuery } from 'queries/useTokenBalanceQuery'; +import { useNativeToken } from 'hooks/useNativeToken'; + +export const ListItem = (props: ListChildComponentProps) => { + const { + index, + style, + data: { fundingAccounts, onSelectionChanged }, + } = props; + + const fundingAccount = fundingAccounts[index]; + + const token = useNativeToken(); + + const { data: balance } = useTokenBalanceQuery(fundingAccount.account_addr, token); + + return ( +
onSelectionChanged(fundingAccount)} + > + + {fundingAccount.account_addr} + + {balance && } +
+ ); +}; diff --git a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/TokenBalance.tsx b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/TokenBalance.tsx new file mode 100644 index 00000000..8c35733e --- /dev/null +++ b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/TokenBalance.tsx @@ -0,0 +1,28 @@ +import { formatAmount, demicrofy } from '@terra-money/apps/libs/formatting'; +import { u } from '@terra-money/apps/types'; +import Big from 'big.js'; +import classNames from 'classnames'; +import { Text } from 'components/primitives'; + +interface TokenBalanceProps { + className: string; + balance: u; + decimals: number; +} + +export const TokenBalance = (props: TokenBalanceProps) => { + const { className, balance, decimals } = props; + + const formattedAmount = + balance === undefined || balance.lte(0) + ? '' + : formatAmount(demicrofy(balance, decimals), { + decimals: 2, + }); + + return ( + + {formattedAmount} + + ); +}; diff --git a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/index.ts b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/index.ts new file mode 100644 index 00000000..ccf4432e --- /dev/null +++ b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/index.ts @@ -0,0 +1 @@ +export * from './FundingAccountList'; From 1317a6ae2f806aec23e7b7539350b4f2c8c066d4 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Wed, 24 Jan 2024 18:06:06 +0100 Subject: [PATCH 24/33] add funding account support in job create flow --- .../components/token-amount/TokenAmount.tsx | 6 ++- .../job-new/details-form/DetailsForm.tsx | 17 +++++-- .../FundingAccountInput.tsx | 12 ++--- .../FundingAccountList.module.sass | 26 ++++++++++- .../FundingAccountList.tsx | 45 +++++++++++++------ .../funding-account-list/ListItem.module.sass | 5 ++- .../funding-account-list/ListItem.tsx | 21 ++++++--- .../job-new/details-form/useDetailsForm.ts | 1 + .../job-new/summary-form/SummaryForm.tsx | 3 +- .../src/pages/job-new/useJobStorage.ts | 1 + apps/warp-protocol/src/tx/useCreateJobTx.ts | 17 ++++++- 11 files changed, 115 insertions(+), 39 deletions(-) diff --git a/apps/warp-protocol/src/components/token-amount/TokenAmount.tsx b/apps/warp-protocol/src/components/token-amount/TokenAmount.tsx index 8747ec35..79dfccb5 100644 --- a/apps/warp-protocol/src/components/token-amount/TokenAmount.tsx +++ b/apps/warp-protocol/src/components/token-amount/TokenAmount.tsx @@ -11,6 +11,7 @@ import styles from './TokenAmount.module.sass'; interface TokenAmountProps extends Pick { className?: string; + containerClassName?: string; token: Token; amount: u; decimals?: number; @@ -32,6 +33,7 @@ export const TokenAmount = (props: TokenAmountProps) => { showSymbol = true, showIcon = false, showUsdAmount = false, + containerClassName, } = props; const formattingOptions = { @@ -48,14 +50,14 @@ export const TokenAmount = (props: TokenAmountProps) => { if (loading) { return ( - + ); } return ( - + {formattedAmount} {showIcon === false && showSymbol && token.symbol && {token.symbol}} diff --git a/apps/warp-protocol/src/pages/job-new/details-form/DetailsForm.tsx b/apps/warp-protocol/src/pages/job-new/details-form/DetailsForm.tsx index 001298a1..9ee9cd02 100644 --- a/apps/warp-protocol/src/pages/job-new/details-form/DetailsForm.tsx +++ b/apps/warp-protocol/src/pages/job-new/details-form/DetailsForm.tsx @@ -48,6 +48,7 @@ export const DetailsForm = (props: DetailsFormProps) => { descriptionError, messageError, submitDisabled, + fundingAccount, recurring, }, ] = useDetailsForm(detailsInput); @@ -151,8 +152,8 @@ export const DetailsForm = (props: DetailsFormProps) => { {}} + value={fundingAccount} + onChange={(acc) => input({ fundingAccount: acc })} /> @@ -217,7 +218,17 @@ export const DetailsForm = (props: DetailsFormProps) => { loading={loading} onClick={async () => { if (name && durationDays && message) { - onNext({ name, durationDays, message, template, selectedTabType, variables, description, recurring }); + onNext({ + name, + durationDays, + message, + template, + selectedTabType, + variables, + description, + recurring, + fundingAccount, + }); } }} > diff --git a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/FundingAccountInput.tsx b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/FundingAccountInput.tsx index 04e02e79..8b8df252 100644 --- a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/FundingAccountInput.tsx +++ b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/FundingAccountInput.tsx @@ -2,15 +2,14 @@ import { Container, UIElementProps } from '@terra-money/apps/components'; import classNames from 'classnames'; import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'; import { FormControl } from 'components/form-control/FormControl'; -import { TokenIcon } from 'components/token-icon'; -import { Token } from '@terra-money/apps/types'; import styles from './FundingAccountInput.module.sass'; import { useFundingAccountListDialog } from './funding-account-list'; +import { truncateAddress } from '@terra-money/apps/utils'; interface FundingAccountInputProps extends UIElementProps { label: string; placeholder?: string; - value?: Token; + value?: string; onChange: (value: string) => void; } @@ -22,13 +21,8 @@ const FundingAccountInput = (props: FundingAccountInputProps) => { const component = value === undefined ? ( {placeholder} - ) : typeof value === 'string' ? ( - {value} ) : ( - <> - - {value.name ?? value.symbol} - + {truncateAddress(value, [8, 6])} ); return ( diff --git a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/FundingAccountList.module.sass b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/FundingAccountList.module.sass index 8b578a8b..fc21a37d 100644 --- a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/FundingAccountList.module.sass +++ b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/FundingAccountList.module.sass @@ -44,4 +44,28 @@ position: absolute top: 50% left: 50% - transform: translate(-50%, -50%) \ No newline at end of file + transform: translate(-50%, -50%) + + + +.tabs + +.tab + border-radius: 16px + text-transform: capitalize + margin-right: 12px + + &:not(.selected_tab) + opacity: 0.4 + + +.new_icon + margin-right: 8px + + +.header + margin-top: 32px + width: 100% + display: flex + align-items: center + justify-content: space-between \ No newline at end of file diff --git a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/FundingAccountList.tsx b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/FundingAccountList.tsx index cf27e157..1aca2efe 100644 --- a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/FundingAccountList.tsx +++ b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/FundingAccountList.tsx @@ -10,14 +10,17 @@ import styles from './FundingAccountList.module.sass'; import { pluralize } from '@terra-money/apps/utils'; import { Container } from '@terra-money/apps/components'; import { warp_account_tracker } from '@terra-money/warp-sdk'; +import { ReactComponent as PlusIcon } from 'components/assets/Plus.svg'; import { useFundingAccountsQuery } from 'queries'; +import { ActionButton } from 'components/action-button/ActionButton'; +import { useCreateFundingAccountTx } from 'tx'; -const accountStatuses = ['taken', 'free'] as warp_account_tracker.AccountStatus[]; +const accountStatuses = ['free', 'taken'] as warp_account_tracker.AccountStatus[]; const FundingAccountListDialog = (props: DialogProps) => { const { closeDialog } = props; - const [selectedAccountStatus, setSelectedAccountStatus] = useState('taken'); + const [selectedAccountStatus, setSelectedAccountStatus] = useState('free'); const { walletAddress } = useLocalWallet(); @@ -37,20 +40,34 @@ const FundingAccountListDialog = (props: DialogProps) => { }; }, [fundingAccounts, closeDialog]); + const [txResult, createFundingAccountTx] = useCreateFundingAccountTx(); + return ( - closeDialog(undefined)}> - - {accountStatuses.map((curr) => ( - - ))} + closeDialog(undefined)}> + + + {accountStatuses.map((curr) => ( + + ))} + + } + iconGap="none" + variant="primary" + loading={txResult.loading} + onClick={() => createFundingAccountTx({})} + > + New + diff --git a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListItem.module.sass b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListItem.module.sass index 99d297f2..67497c8f 100644 --- a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListItem.module.sass +++ b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListItem.module.sass @@ -14,9 +14,10 @@ grid-row: 1 / span 2 grid-column: 1 margin-right: 16px - .symbol - grid-row: 1 + .account_addr + grid-row: 1 / span 2 grid-column: 2 + font-weight: 400 !important color: var(--text-color-title) .name grid-row: 2 diff --git a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListItem.tsx b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListItem.tsx index 91ee3d2b..15e2880d 100644 --- a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListItem.tsx +++ b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/ListItem.tsx @@ -1,10 +1,13 @@ import { Text } from 'components/primitives'; import { ListChildComponentProps } from 'react-window'; -import { TokenBalance } from './TokenBalance'; import { ListData } from './ListData'; import styles from './ListItem.module.sass'; import { useTokenBalanceQuery } from 'queries/useTokenBalanceQuery'; import { useNativeToken } from 'hooks/useNativeToken'; +import { truncateAddress } from '@terra-money/apps/utils'; +import { TokenAmount } from 'components/token-amount'; +import Big from 'big.js'; +import { u } from '@terra-money/apps/types'; export const ListItem = (props: ListChildComponentProps) => { const { @@ -17,7 +20,7 @@ export const ListItem = (props: ListChildComponentProps) => { const token = useNativeToken(); - const { data: balance } = useTokenBalanceQuery(fundingAccount.account_addr, token); + const { data: balance, isLoading } = useTokenBalanceQuery(fundingAccount.account_addr, token); return (
) => { style={style} onClick={() => onSelectionChanged(fundingAccount)} > - - {fundingAccount.account_addr} + + {truncateAddress(fundingAccount.account_addr, [8, 6])} - {balance && } + )} + showSymbol={true} + />
); }; diff --git a/apps/warp-protocol/src/pages/job-new/details-form/useDetailsForm.ts b/apps/warp-protocol/src/pages/job-new/details-form/useDetailsForm.ts index 7383dd94..816c33c2 100644 --- a/apps/warp-protocol/src/pages/job-new/details-form/useDetailsForm.ts +++ b/apps/warp-protocol/src/pages/job-new/details-form/useDetailsForm.ts @@ -22,6 +22,7 @@ export interface DetailsFormInput { durationDays: string; message: string; recurring: boolean; + fundingAccount?: string; template?: Template; selectedTabType?: 'template' | 'message'; } diff --git a/apps/warp-protocol/src/pages/job-new/summary-form/SummaryForm.tsx b/apps/warp-protocol/src/pages/job-new/summary-form/SummaryForm.tsx index d3139354..0006ac2a 100644 --- a/apps/warp-protocol/src/pages/job-new/summary-form/SummaryForm.tsx +++ b/apps/warp-protocol/src/pages/job-new/summary-form/SummaryForm.tsx @@ -159,7 +159,7 @@ export const SummaryForm = (props: SummaryFormProps) => { disabled={!reward || !operationalAmount} onClick={async () => { if (detailsInput && operationalAmount && reward) { - const { name, message, description, recurring, durationDays } = detailsInput; + const { name, message, description, recurring, durationDays, fundingAccount } = detailsInput; const msgs = parseMsgs(message); @@ -175,6 +175,7 @@ export const SummaryForm = (props: SummaryFormProps) => { operationalAmount, reward, durationDays, + fundingAccount, }); if (resp.code !== 0) { diff --git a/apps/warp-protocol/src/pages/job-new/useJobStorage.ts b/apps/warp-protocol/src/pages/job-new/useJobStorage.ts index b13dd42d..ed1cdc56 100644 --- a/apps/warp-protocol/src/pages/job-new/useJobStorage.ts +++ b/apps/warp-protocol/src/pages/job-new/useJobStorage.ts @@ -31,6 +31,7 @@ export const useJobStorage = () => { description: job.info.description, message: JSON.stringify(job.msgs, null, 2), recurring: job.info.recurring, + fundingAccount: job.info.funding_account ?? undefined, }; setDetailsInput(details); diff --git a/apps/warp-protocol/src/tx/useCreateJobTx.ts b/apps/warp-protocol/src/tx/useCreateJobTx.ts index ead2cd31..a0696dbe 100644 --- a/apps/warp-protocol/src/tx/useCreateJobTx.ts +++ b/apps/warp-protocol/src/tx/useCreateJobTx.ts @@ -15,6 +15,7 @@ export interface CreateJobTxProps { operationalAmount: string; reward: string; recurring: boolean; + fundingAccount?: string; } export const useCreateJobTx = () => { @@ -22,8 +23,19 @@ export const useCreateJobTx = () => { return useTx( async (options) => { - const { wallet, name, msgs, condition, vars, description, recurring, durationDays, operationalAmount, reward } = - options; + const { + wallet, + name, + msgs, + condition, + vars, + description, + recurring, + durationDays, + operationalAmount, + reward, + fundingAccount, + } = options; if (!containsAllReferencedVars(vars, msgs, condition)) { throw Error( @@ -45,6 +57,7 @@ export const useCreateJobTx = () => { .recurring(recurring) .description(description) .vars(orderedVars) + .fundingAccount(fundingAccount) .durationDays(durationDays) .executions(executions) .compose(); From 966769cab3c5f205bf03c275b57305e8fb591b53 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Thu, 25 Jan 2024 00:47:55 +0100 Subject: [PATCH 25/33] fix details form validation --- .../funding-account-list/FundingAccountList.tsx | 2 +- .../src/pages/job-new/details-form/useDetailsForm.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/FundingAccountList.tsx b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/FundingAccountList.tsx index 1aca2efe..ac57c8fc 100644 --- a/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/FundingAccountList.tsx +++ b/apps/warp-protocol/src/pages/job-new/details-form/funding-account-input/funding-account-list/FundingAccountList.tsx @@ -78,7 +78,7 @@ const FundingAccountListDialog = (props: DialogProps) => { direction="row" > {`Displaying ${listData.fundingAccounts.length} ${pluralize( - 'funding accounts', + 'funding account', listData.fundingAccounts.length )}`} Balance diff --git a/apps/warp-protocol/src/pages/job-new/details-form/useDetailsForm.ts b/apps/warp-protocol/src/pages/job-new/details-form/useDetailsForm.ts index 816c33c2..36d462b3 100644 --- a/apps/warp-protocol/src/pages/job-new/details-form/useDetailsForm.ts +++ b/apps/warp-protocol/src/pages/job-new/details-form/useDetailsForm.ts @@ -123,6 +123,9 @@ export const useDetailsForm = (input?: DetailsFormInput) => { state.name === undefined || state.name === null || state.name.length < 1 || + state.durationDays === undefined || + state.durationDays === null || + state.durationDays.length < 1 || nameError || descriptionError || state.message === undefined || From 69f989bead58d9674803e9de72ef68ee17cf7ea8 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Mon, 29 Jan 2024 16:38:15 +0100 Subject: [PATCH 26/33] add staging sdk version --- apps/shared/package.json | 2 +- apps/warp-protocol/package.json | 2 +- indexers/warp-protocol/package.json | 2 +- yarn.lock | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/shared/package.json b/apps/shared/package.json index 1440a603..e78afdc2 100644 --- a/apps/shared/package.json +++ b/apps/shared/package.json @@ -33,7 +33,7 @@ "@mui/material": "^5.10.2", "@terra-money/feather.js": "^1.0.11", "@terra-money/wallet-kit": "^1.0.11", - "@terra-money/warp-sdk": "^0.1.61", + "@terra-money/warp-sdk": "0.1.70-rc1", "assert": "^2.0.0", "big.js": "^6.2.1", "buffer": "^6.0.3", diff --git a/apps/warp-protocol/package.json b/apps/warp-protocol/package.json index 25bb2476..0d26cffa 100644 --- a/apps/warp-protocol/package.json +++ b/apps/warp-protocol/package.json @@ -41,7 +41,7 @@ "@popperjs/core": "^2.11.6", "@terra-money/feather.js": "^1.0.11", "@terra-money/wallet-kit": "^1.0.11", - "@terra-money/warp-sdk": "^0.1.61", + "@terra-money/warp-sdk": "0.1.70-rc1", "assert": "^2.0.0", "big.js": "^6.2.1", "brace": "^0.11.1", diff --git a/indexers/warp-protocol/package.json b/indexers/warp-protocol/package.json index 82053429..4dfdad8a 100644 --- a/indexers/warp-protocol/package.json +++ b/indexers/warp-protocol/package.json @@ -16,7 +16,7 @@ "@aws-sdk/client-dynamodb": "^3.159.0", "@aws-sdk/util-dynamodb": "^3.159.0", "@terra-money/feather.js": "^1.0.11", - "@terra-money/warp-sdk": "^0.1.61", + "@terra-money/warp-sdk": "0.1.70-rc1", "@types/node": "^16.11.56", "axios": "^1.1.2", "big.js": "^6.2.1", diff --git a/yarn.lock b/yarn.lock index 4367ad71..48cc6d80 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4322,7 +4322,7 @@ __metadata: "@mui/material": ^5.10.2 "@terra-money/feather.js": ^1.0.11 "@terra-money/wallet-kit": ^1.0.11 - "@terra-money/warp-sdk": ^0.1.61 + "@terra-money/warp-sdk": 0.1.70-rc1 "@testing-library/jest-dom": ^5.16.5 "@testing-library/react": ^13.3.0 "@testing-library/user-event": ^13.5.0 @@ -4468,9 +4468,9 @@ __metadata: languageName: node linkType: hard -"@terra-money/warp-sdk@npm:^0.1.61": - version: 0.1.61 - resolution: "@terra-money/warp-sdk@npm:0.1.61" +"@terra-money/warp-sdk@npm:0.1.70-rc1": + version: 0.1.70-rc1 + resolution: "@terra-money/warp-sdk@npm:0.1.70-rc1" dependencies: "@terra-money/feather.js": ^1.0.11 "@types/node": ^16.11.56 @@ -4483,7 +4483,7 @@ __metadata: lodash: ^4.17.21 pino: ^8.4.2 typescript: ^4.8.2 - checksum: 5afca96779e0be646e1140330e905cfd4bfe586e2e9e1a1596fcca03136f1f3ca4e712194fadc8ce91a222a0ec5af600bb5723faad01d7e2814733e63ea109e9 + checksum: 21bd2f242c16ed19e515874bb84d716e2b170114f1c40284fe69685ce5836621999a65d90ea080cc1cf1313c9de932a62f26b4506d90345c3bdc096e23574e30 languageName: node linkType: hard @@ -5406,7 +5406,7 @@ __metadata: "@popperjs/core": ^2.11.6 "@terra-money/feather.js": ^1.0.11 "@terra-money/wallet-kit": ^1.0.11 - "@terra-money/warp-sdk": ^0.1.61 + "@terra-money/warp-sdk": 0.1.70-rc1 "@testing-library/jest-dom": ^5.16.5 "@testing-library/react": ^13.3.0 "@testing-library/user-event": ^13.5.0 @@ -5483,7 +5483,7 @@ __metadata: "@aws-sdk/client-dynamodb": ^3.159.0 "@aws-sdk/util-dynamodb": ^3.159.0 "@terra-money/feather.js": ^1.0.11 - "@terra-money/warp-sdk": ^0.1.61 + "@terra-money/warp-sdk": 0.1.70-rc1 "@types/d3-array": ^3.0.3 "@types/node": ^16.11.56 axios: ^1.1.2 From 3f3a68ee16f499880a1d62fdae9dc8cd04578a00 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Fri, 2 Feb 2024 16:28:39 +0100 Subject: [PATCH 27/33] new sdk v --- apps/shared/package.json | 2 +- apps/warp-protocol/package.json | 2 +- indexers/warp-protocol/package.json | 2 +- yarn.lock | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/shared/package.json b/apps/shared/package.json index e78afdc2..70e24362 100644 --- a/apps/shared/package.json +++ b/apps/shared/package.json @@ -33,7 +33,7 @@ "@mui/material": "^5.10.2", "@terra-money/feather.js": "^1.0.11", "@terra-money/wallet-kit": "^1.0.11", - "@terra-money/warp-sdk": "0.1.70-rc1", + "@terra-money/warp-sdk": "0.1.71-rc3", "assert": "^2.0.0", "big.js": "^6.2.1", "buffer": "^6.0.3", diff --git a/apps/warp-protocol/package.json b/apps/warp-protocol/package.json index 0d26cffa..adb3b2cb 100644 --- a/apps/warp-protocol/package.json +++ b/apps/warp-protocol/package.json @@ -41,7 +41,7 @@ "@popperjs/core": "^2.11.6", "@terra-money/feather.js": "^1.0.11", "@terra-money/wallet-kit": "^1.0.11", - "@terra-money/warp-sdk": "0.1.70-rc1", + "@terra-money/warp-sdk": "0.1.71-rc3", "assert": "^2.0.0", "big.js": "^6.2.1", "brace": "^0.11.1", diff --git a/indexers/warp-protocol/package.json b/indexers/warp-protocol/package.json index 4dfdad8a..b1ee6851 100644 --- a/indexers/warp-protocol/package.json +++ b/indexers/warp-protocol/package.json @@ -16,7 +16,7 @@ "@aws-sdk/client-dynamodb": "^3.159.0", "@aws-sdk/util-dynamodb": "^3.159.0", "@terra-money/feather.js": "^1.0.11", - "@terra-money/warp-sdk": "0.1.70-rc1", + "@terra-money/warp-sdk": "0.1.71-rc3", "@types/node": "^16.11.56", "axios": "^1.1.2", "big.js": "^6.2.1", diff --git a/yarn.lock b/yarn.lock index 48cc6d80..723618e0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4322,7 +4322,7 @@ __metadata: "@mui/material": ^5.10.2 "@terra-money/feather.js": ^1.0.11 "@terra-money/wallet-kit": ^1.0.11 - "@terra-money/warp-sdk": 0.1.70-rc1 + "@terra-money/warp-sdk": 0.1.71-rc3 "@testing-library/jest-dom": ^5.16.5 "@testing-library/react": ^13.3.0 "@testing-library/user-event": ^13.5.0 @@ -4468,9 +4468,9 @@ __metadata: languageName: node linkType: hard -"@terra-money/warp-sdk@npm:0.1.70-rc1": - version: 0.1.70-rc1 - resolution: "@terra-money/warp-sdk@npm:0.1.70-rc1" +"@terra-money/warp-sdk@npm:0.1.71-rc3": + version: 0.1.71-rc3 + resolution: "@terra-money/warp-sdk@npm:0.1.71-rc3" dependencies: "@terra-money/feather.js": ^1.0.11 "@types/node": ^16.11.56 @@ -4483,7 +4483,7 @@ __metadata: lodash: ^4.17.21 pino: ^8.4.2 typescript: ^4.8.2 - checksum: 21bd2f242c16ed19e515874bb84d716e2b170114f1c40284fe69685ce5836621999a65d90ea080cc1cf1313c9de932a62f26b4506d90345c3bdc096e23574e30 + checksum: d08ee19e20bd98af7ba3a0f8bdf3518cab62b5022d80e607330afaa45d68629c7c4dc2cfd4fe9424b9c91864113014aa9b0aff66460e0f43ff70c0f7f1ec9fd8 languageName: node linkType: hard @@ -5406,7 +5406,7 @@ __metadata: "@popperjs/core": ^2.11.6 "@terra-money/feather.js": ^1.0.11 "@terra-money/wallet-kit": ^1.0.11 - "@terra-money/warp-sdk": 0.1.70-rc1 + "@terra-money/warp-sdk": 0.1.71-rc3 "@testing-library/jest-dom": ^5.16.5 "@testing-library/react": ^13.3.0 "@testing-library/user-event": ^13.5.0 @@ -5483,7 +5483,7 @@ __metadata: "@aws-sdk/client-dynamodb": ^3.159.0 "@aws-sdk/util-dynamodb": ^3.159.0 "@terra-money/feather.js": ^1.0.11 - "@terra-money/warp-sdk": 0.1.70-rc1 + "@terra-money/warp-sdk": 0.1.71-rc3 "@types/d3-array": ^3.0.3 "@types/node": ^16.11.56 axios: ^1.1.2 From 33d89ef7f0631e866713cf20405918c59566c7c1 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Mon, 5 Feb 2024 17:17:42 +0100 Subject: [PATCH 28/33] new skd v --- apps/shared/package.json | 2 +- apps/warp-protocol/package.json | 2 +- indexers/warp-protocol/package.json | 2 +- yarn.lock | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/shared/package.json b/apps/shared/package.json index 70e24362..a5afe7c0 100644 --- a/apps/shared/package.json +++ b/apps/shared/package.json @@ -33,7 +33,7 @@ "@mui/material": "^5.10.2", "@terra-money/feather.js": "^1.0.11", "@terra-money/wallet-kit": "^1.0.11", - "@terra-money/warp-sdk": "0.1.71-rc3", + "@terra-money/warp-sdk": "0.1.71-rc11", "assert": "^2.0.0", "big.js": "^6.2.1", "buffer": "^6.0.3", diff --git a/apps/warp-protocol/package.json b/apps/warp-protocol/package.json index adb3b2cb..487e84ad 100644 --- a/apps/warp-protocol/package.json +++ b/apps/warp-protocol/package.json @@ -41,7 +41,7 @@ "@popperjs/core": "^2.11.6", "@terra-money/feather.js": "^1.0.11", "@terra-money/wallet-kit": "^1.0.11", - "@terra-money/warp-sdk": "0.1.71-rc3", + "@terra-money/warp-sdk": "0.1.71-rc11", "assert": "^2.0.0", "big.js": "^6.2.1", "brace": "^0.11.1", diff --git a/indexers/warp-protocol/package.json b/indexers/warp-protocol/package.json index b1ee6851..2472e1b5 100644 --- a/indexers/warp-protocol/package.json +++ b/indexers/warp-protocol/package.json @@ -16,7 +16,7 @@ "@aws-sdk/client-dynamodb": "^3.159.0", "@aws-sdk/util-dynamodb": "^3.159.0", "@terra-money/feather.js": "^1.0.11", - "@terra-money/warp-sdk": "0.1.71-rc3", + "@terra-money/warp-sdk": "0.1.71-rc11", "@types/node": "^16.11.56", "axios": "^1.1.2", "big.js": "^6.2.1", diff --git a/yarn.lock b/yarn.lock index 723618e0..7ffaddb3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4322,7 +4322,7 @@ __metadata: "@mui/material": ^5.10.2 "@terra-money/feather.js": ^1.0.11 "@terra-money/wallet-kit": ^1.0.11 - "@terra-money/warp-sdk": 0.1.71-rc3 + "@terra-money/warp-sdk": 0.1.71-rc11 "@testing-library/jest-dom": ^5.16.5 "@testing-library/react": ^13.3.0 "@testing-library/user-event": ^13.5.0 @@ -4468,9 +4468,9 @@ __metadata: languageName: node linkType: hard -"@terra-money/warp-sdk@npm:0.1.71-rc3": - version: 0.1.71-rc3 - resolution: "@terra-money/warp-sdk@npm:0.1.71-rc3" +"@terra-money/warp-sdk@npm:0.1.71-rc11": + version: 0.1.71-rc11 + resolution: "@terra-money/warp-sdk@npm:0.1.71-rc11" dependencies: "@terra-money/feather.js": ^1.0.11 "@types/node": ^16.11.56 @@ -4483,7 +4483,7 @@ __metadata: lodash: ^4.17.21 pino: ^8.4.2 typescript: ^4.8.2 - checksum: d08ee19e20bd98af7ba3a0f8bdf3518cab62b5022d80e607330afaa45d68629c7c4dc2cfd4fe9424b9c91864113014aa9b0aff66460e0f43ff70c0f7f1ec9fd8 + checksum: 84d3c4532bf6ae7694612f9f538e51bcb446dd99e123df70e35ce5329fdb3c912aa1e72b891bc59d2657abca0fbd95d459498124c58b3715195f2d9bd298a0b0 languageName: node linkType: hard @@ -5406,7 +5406,7 @@ __metadata: "@popperjs/core": ^2.11.6 "@terra-money/feather.js": ^1.0.11 "@terra-money/wallet-kit": ^1.0.11 - "@terra-money/warp-sdk": 0.1.71-rc3 + "@terra-money/warp-sdk": 0.1.71-rc11 "@testing-library/jest-dom": ^5.16.5 "@testing-library/react": ^13.3.0 "@testing-library/user-event": ^13.5.0 @@ -5483,7 +5483,7 @@ __metadata: "@aws-sdk/client-dynamodb": ^3.159.0 "@aws-sdk/util-dynamodb": ^3.159.0 "@terra-money/feather.js": ^1.0.11 - "@terra-money/warp-sdk": 0.1.71-rc3 + "@terra-money/warp-sdk": 0.1.71-rc11 "@types/d3-array": ^3.0.3 "@types/node": ^16.11.56 axios: ^1.1.2 From f2b9b2d0068ed20378d08847638168dce44cb652 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Tue, 13 Feb 2024 18:17:33 +0100 Subject: [PATCH 29/33] change editor input + new version --- apps/shared/package.json | 2 +- apps/warp-protocol/package.json | 2 +- .../src/forms/QueryExprForm/EditorInput.tsx | 31 +++++++++++++------ indexers/warp-protocol/package.json | 2 +- yarn.lock | 14 ++++----- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/apps/shared/package.json b/apps/shared/package.json index a5afe7c0..d59c2d39 100644 --- a/apps/shared/package.json +++ b/apps/shared/package.json @@ -33,7 +33,7 @@ "@mui/material": "^5.10.2", "@terra-money/feather.js": "^1.0.11", "@terra-money/wallet-kit": "^1.0.11", - "@terra-money/warp-sdk": "0.1.71-rc11", + "@terra-money/warp-sdk": "0.1.71-rc12", "assert": "^2.0.0", "big.js": "^6.2.1", "buffer": "^6.0.3", diff --git a/apps/warp-protocol/package.json b/apps/warp-protocol/package.json index 487e84ad..affe7e33 100644 --- a/apps/warp-protocol/package.json +++ b/apps/warp-protocol/package.json @@ -41,7 +41,7 @@ "@popperjs/core": "^2.11.6", "@terra-money/feather.js": "^1.0.11", "@terra-money/wallet-kit": "^1.0.11", - "@terra-money/warp-sdk": "0.1.71-rc11", + "@terra-money/warp-sdk": "0.1.71-rc12", "assert": "^2.0.0", "big.js": "^6.2.1", "brace": "^0.11.1", diff --git a/apps/warp-protocol/src/forms/QueryExprForm/EditorInput.tsx b/apps/warp-protocol/src/forms/QueryExprForm/EditorInput.tsx index d4f49676..65a598e2 100644 --- a/apps/warp-protocol/src/forms/QueryExprForm/EditorInput.tsx +++ b/apps/warp-protocol/src/forms/QueryExprForm/EditorInput.tsx @@ -14,8 +14,9 @@ import { SuggestItemsMenu } from './SuggestItemsMenu'; import { variableName } from 'utils/variable'; import CustomJsonSyntaxMode from './CustomJsonSyntaxMode'; import { IAceEditor } from 'react-ace/lib/types'; -import { warp_resolver } from '@terra-money/warp-sdk'; -import { useLocalWallet } from '@terra-money/apps/hooks'; +import { base64encode, warp_resolver } from '@terra-money/warp-sdk'; +import { useWarpSdk } from '@terra-money/apps/hooks'; +import { useQueryExample } from 'pages/variables/details/query/QueryVariableForm'; export interface EditorInputProps { className?: string; @@ -41,19 +42,31 @@ export interface EditorInputProps { onEditorCursorChange?: (editor: IAceEditor) => void; } -const defaultExample = (walletAddr: string): warp_resolver.WarpMsg => ({ +const defaultExample = ( + contractAddress: string, + query: warp_resolver.QueryRequestFor_String +): warp_resolver.WarpMsg => ({ generic: { - bank: { - send: { - amount: [{ amount: '1000000', denom: 'uluna' }], - to_address: walletAddr, + wasm: { + execute: { + msg: base64encode({ + execute_simulate_query: { + query, + }, + }), + funds: [], + contract_addr: contractAddress, }, }, }, }); const EditorInput = (props: EditorInputProps) => { - const { walletAddress } = useLocalWallet(); + const sdk = useWarpSdk(); + + const queryExample = useQueryExample(); + + console.log({ contracts: sdk.chain.contracts }); const { endLabel, @@ -67,7 +80,7 @@ const EditorInput = (props: EditorInputProps) => { mode = 'json', onChange, readOnly, - example = defaultExample(walletAddress), + example = defaultExample(sdk.chain.contracts.resolver, queryExample), onEditorCursorChange, suggestItems, } = props; diff --git a/indexers/warp-protocol/package.json b/indexers/warp-protocol/package.json index 2472e1b5..36b7ae16 100644 --- a/indexers/warp-protocol/package.json +++ b/indexers/warp-protocol/package.json @@ -16,7 +16,7 @@ "@aws-sdk/client-dynamodb": "^3.159.0", "@aws-sdk/util-dynamodb": "^3.159.0", "@terra-money/feather.js": "^1.0.11", - "@terra-money/warp-sdk": "0.1.71-rc11", + "@terra-money/warp-sdk": "0.1.71-rc12", "@types/node": "^16.11.56", "axios": "^1.1.2", "big.js": "^6.2.1", diff --git a/yarn.lock b/yarn.lock index 7ffaddb3..93c162e2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4322,7 +4322,7 @@ __metadata: "@mui/material": ^5.10.2 "@terra-money/feather.js": ^1.0.11 "@terra-money/wallet-kit": ^1.0.11 - "@terra-money/warp-sdk": 0.1.71-rc11 + "@terra-money/warp-sdk": 0.1.71-rc12 "@testing-library/jest-dom": ^5.16.5 "@testing-library/react": ^13.3.0 "@testing-library/user-event": ^13.5.0 @@ -4468,9 +4468,9 @@ __metadata: languageName: node linkType: hard -"@terra-money/warp-sdk@npm:0.1.71-rc11": - version: 0.1.71-rc11 - resolution: "@terra-money/warp-sdk@npm:0.1.71-rc11" +"@terra-money/warp-sdk@npm:0.1.71-rc12": + version: 0.1.71-rc12 + resolution: "@terra-money/warp-sdk@npm:0.1.71-rc12" dependencies: "@terra-money/feather.js": ^1.0.11 "@types/node": ^16.11.56 @@ -4483,7 +4483,7 @@ __metadata: lodash: ^4.17.21 pino: ^8.4.2 typescript: ^4.8.2 - checksum: 84d3c4532bf6ae7694612f9f538e51bcb446dd99e123df70e35ce5329fdb3c912aa1e72b891bc59d2657abca0fbd95d459498124c58b3715195f2d9bd298a0b0 + checksum: 2902336569783ffc0e9abfadbf6e9b3fbf5ced5d74cdbcea81aaa7013e3375c1235c4fc9a0cd04ee318e950eea72fb90648a39f93aece0f58a5f21a94b06c5f2 languageName: node linkType: hard @@ -5406,7 +5406,7 @@ __metadata: "@popperjs/core": ^2.11.6 "@terra-money/feather.js": ^1.0.11 "@terra-money/wallet-kit": ^1.0.11 - "@terra-money/warp-sdk": 0.1.71-rc11 + "@terra-money/warp-sdk": 0.1.71-rc12 "@testing-library/jest-dom": ^5.16.5 "@testing-library/react": ^13.3.0 "@testing-library/user-event": ^13.5.0 @@ -5483,7 +5483,7 @@ __metadata: "@aws-sdk/client-dynamodb": ^3.159.0 "@aws-sdk/util-dynamodb": ^3.159.0 "@terra-money/feather.js": ^1.0.11 - "@terra-money/warp-sdk": 0.1.71-rc11 + "@terra-money/warp-sdk": 0.1.71-rc12 "@types/d3-array": ^3.0.3 "@types/node": ^16.11.56 axios: ^1.1.2 From f1496973a2682f9211a9ab6b612bce1402f9efc2 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Mon, 19 Feb 2024 17:32:27 +0100 Subject: [PATCH 30/33] landing page updates --- apps/warp-protocol-landing/src/App.tsx | 12 ++++++++++++ .../src/bottom-bar/BottomBar.tsx | 3 +++ .../src/bottom-bar/DesktopBottomBar.tsx | 12 +++++++++++- .../src/pages/home/Home.tsx | 4 +++- .../src/pages/home/top-content/TopContent.tsx | 11 ++++++----- .../src/top-bar/DesktopTopBar.tsx | 19 +++++++++++++++---- .../src/top-bar/MobileTopBar.tsx | 18 ++++++++++++++++++ .../src/top-bar/TopBar.tsx | 8 ++++++++ 8 files changed, 76 insertions(+), 11 deletions(-) diff --git a/apps/warp-protocol-landing/src/App.tsx b/apps/warp-protocol-landing/src/App.tsx index e0c1a80d..ae841b64 100644 --- a/apps/warp-protocol-landing/src/App.tsx +++ b/apps/warp-protocol-landing/src/App.tsx @@ -55,6 +55,10 @@ const App = () => { window.open('https://twitter.com/warp_protocol'); }, []); + const onGetInTouchClick = useCallback(() => { + window.open('https://forms.gle/AVfrfDStd95qjnGQ9'); + }, []); + const onTelegramClick = useCallback(() => { window.open('https://t.me/warp_protocol'); }, []); @@ -63,6 +67,10 @@ const App = () => { window.open('https://terra.sc/warpdiscord'); }, []); + const onSdkClick = useCallback(() => { + window.open('https://github.com/terra-money/warp-sdk'); + }, []); + const onPrivacyPolicyClick = useCallback(() => { window.open(`${baseUrl(document.location.href)}/pdfs/privacy_policy.pdf`); }, []); @@ -84,6 +92,8 @@ const App = () => { onTwitterClick={onTwitterClick} onTelegramClick={onTelegramClick} onDiscordClick={onDiscordClick} + onSdkClick={onSdkClick} + onGetInTouchClick={onGetInTouchClick} /> { } @@ -103,6 +114,7 @@ const App = () => { void; onTelegramClick: () => void; onTwitterClick: () => void; + onSdkClick: () => void; onBrandClick: () => void; }; @@ -28,6 +29,7 @@ export const BottomBar = (props: BottomBarProps) => { onTelegramClick, onTwitterClick, onBrandClick, + onSdkClick, } = props; const isMobile = useMediaQuery('(max-width: 768px)'); @@ -53,6 +55,7 @@ export const BottomBar = (props: BottomBarProps) => { onTelegramClick={onTelegramClick} onTwitterClick={onTwitterClick} onBrandClick={onBrandClick} + onSdkClick={onSdkClick} /> ); }; diff --git a/apps/warp-protocol-landing/src/bottom-bar/DesktopBottomBar.tsx b/apps/warp-protocol-landing/src/bottom-bar/DesktopBottomBar.tsx index acf34a1c..7b3d35a3 100644 --- a/apps/warp-protocol-landing/src/bottom-bar/DesktopBottomBar.tsx +++ b/apps/warp-protocol-landing/src/bottom-bar/DesktopBottomBar.tsx @@ -18,6 +18,7 @@ type DesktopBottomBarProps = UIElementProps & { onTelegramClick: () => void; onTwitterClick: () => void; onBrandClick: () => void; + onSdkClick: () => void; }; export const DesktopBottomBar = (props: DesktopBottomBarProps) => { @@ -31,7 +32,8 @@ export const DesktopBottomBar = (props: DesktopBottomBarProps) => { onDiscordClick, onTelegramClick, onTwitterClick, - onBrandClick + onBrandClick, + onSdkClick } = props; return ( @@ -56,6 +58,14 @@ export const DesktopBottomBar = (props: DesktopBottomBarProps) => { > Docs +
diff --git a/apps/warp-protocol-landing/src/top-bar/DesktopTopBar.tsx b/apps/warp-protocol-landing/src/top-bar/DesktopTopBar.tsx index fe4864a1..578cf190 100644 --- a/apps/warp-protocol-landing/src/top-bar/DesktopTopBar.tsx +++ b/apps/warp-protocol-landing/src/top-bar/DesktopTopBar.tsx @@ -16,6 +16,8 @@ type DesktopTopBarProps = UIElementProps & { onTelegramClick: () => void; onDiscordClick: () => void; onTwitterClick: () => void; + onSdkClick: () => void; + onGetInTouchClick: () => void; }; export const DesktopTopBar = forwardRef< @@ -26,10 +28,11 @@ export const DesktopTopBar = forwardRef< onHomeClick, onFeaturesClick, onDocsClick, - onWebAppClick, onTelegramClick, onDiscordClick, - onTwitterClick + onTwitterClick, + onSdkClick, + onGetInTouchClick, } = props; return ( @@ -64,6 +67,14 @@ export const DesktopTopBar = forwardRef< > Features + - Launch App + Get in Touch diff --git a/apps/warp-protocol-landing/src/top-bar/MobileTopBar.tsx b/apps/warp-protocol-landing/src/top-bar/MobileTopBar.tsx index 1c86a354..eaa303a2 100644 --- a/apps/warp-protocol-landing/src/top-bar/MobileTopBar.tsx +++ b/apps/warp-protocol-landing/src/top-bar/MobileTopBar.tsx @@ -20,6 +20,8 @@ type MobileTopBarProps = UIElementProps & { onTelegramClick: () => void; onTwitterClick: () => void; onToggleDrawer: () => void; + onSdkClick: () => void; + onGetInTouchClick: () => void; drawerOpen: boolean; }; @@ -36,6 +38,8 @@ export const MobileTopBar = forwardRef< onTelegramClick, onTwitterClick, onToggleDrawer, + onGetInTouchClick, + onSdkClick, drawerOpen, } = props; @@ -90,6 +94,13 @@ export const MobileTopBar = forwardRef< > Features + + SDK + App + + Get in Touch + void; onTwitterClick: () => void; onTelegramClick: () => void; + onSdkClick: () => void; + onGetInTouchClick: () => void; }; export const TopBar = forwardRef( @@ -29,6 +31,8 @@ export const TopBar = forwardRef( onDiscordClick, onTelegramClick, onTwitterClick, + onSdkClick, + onGetInTouchClick } = props; const isMobile = useMediaQuery('(max-width: 768px)'); @@ -46,6 +50,8 @@ export const TopBar = forwardRef( onDocsClick={onDocsClick} onFeaturesClick={onFeaturesClick} onWebAppClick={onWebAppClick} + onSdkClick={onSdkClick} + onGetInTouchClick={onGetInTouchClick} /> ); } @@ -60,6 +66,8 @@ export const TopBar = forwardRef( onFeaturesClick={onFeaturesClick} onWebAppClick={onWebAppClick} onTwitterClick={onTwitterClick} + onSdkClick={onSdkClick} + onGetInTouchClick={onGetInTouchClick} /> ); } From 5c4d3733a46433ffefbeecdafb67d061836bb39e Mon Sep 17 00:00:00 2001 From: simke9445 Date: Wed, 21 Feb 2024 15:48:18 +0100 Subject: [PATCH 31/33] temporarily disable injective --- apps/shared/hooks/useChainSelector.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/shared/hooks/useChainSelector.tsx b/apps/shared/hooks/useChainSelector.tsx index b6d3e29c..4f812078 100644 --- a/apps/shared/hooks/useChainSelector.tsx +++ b/apps/shared/hooks/useChainSelector.tsx @@ -131,7 +131,8 @@ const ChainSelectorProvider = (props: ChainSelectorProviderProps) => { .filter((c) => { if ( (c.name === 'nibiru' && networkName(network) === 'mainnet') || - (c.name === 'migaloo' && networkName(network) === 'mainnet') + (c.name === 'migaloo' && networkName(network) === 'mainnet') || + (c.name === 'injective' && networkName(network) === 'mainnet') ) { return false; } From 44a75d3f9291f81d73ad0b3b65c28554317107e9 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Wed, 21 Feb 2024 16:15:30 +0100 Subject: [PATCH 32/33] reeneable injective --- apps/shared/hooks/useChainSelector.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/shared/hooks/useChainSelector.tsx b/apps/shared/hooks/useChainSelector.tsx index 4f812078..b6d3e29c 100644 --- a/apps/shared/hooks/useChainSelector.tsx +++ b/apps/shared/hooks/useChainSelector.tsx @@ -131,8 +131,7 @@ const ChainSelectorProvider = (props: ChainSelectorProviderProps) => { .filter((c) => { if ( (c.name === 'nibiru' && networkName(network) === 'mainnet') || - (c.name === 'migaloo' && networkName(network) === 'mainnet') || - (c.name === 'injective' && networkName(network) === 'mainnet') + (c.name === 'migaloo' && networkName(network) === 'mainnet') ) { return false; } From 2c701c5ff1ac9bf84bcd45afbf2dc716d71f3ed7 Mon Sep 17 00:00:00 2001 From: simke9445 Date: Wed, 21 Feb 2024 17:01:03 +0100 Subject: [PATCH 33/33] feature/latest_updates --- apps/shared/package.json | 2 +- apps/warp-protocol/package.json | 2 +- indexers/warp-protocol/package.json | 2 +- yarn.lock | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/shared/package.json b/apps/shared/package.json index d59c2d39..213df19c 100644 --- a/apps/shared/package.json +++ b/apps/shared/package.json @@ -33,7 +33,7 @@ "@mui/material": "^5.10.2", "@terra-money/feather.js": "^1.0.11", "@terra-money/wallet-kit": "^1.0.11", - "@terra-money/warp-sdk": "0.1.71-rc12", + "@terra-money/warp-sdk": "^0.2.2", "assert": "^2.0.0", "big.js": "^6.2.1", "buffer": "^6.0.3", diff --git a/apps/warp-protocol/package.json b/apps/warp-protocol/package.json index 43ded09b..37047b7a 100644 --- a/apps/warp-protocol/package.json +++ b/apps/warp-protocol/package.json @@ -42,7 +42,7 @@ "@terra-money/feather.js": "^1.0.11", "@terra-money/terra-station-mobile": "1.0.8", "@terra-money/wallet-kit": "^1.0.11", - "@terra-money/warp-sdk": "0.1.71-rc12", + "@terra-money/warp-sdk": "^0.2.2", "assert": "^2.0.0", "big.js": "^6.2.1", "brace": "^0.11.1", diff --git a/indexers/warp-protocol/package.json b/indexers/warp-protocol/package.json index 36b7ae16..d861b0b0 100644 --- a/indexers/warp-protocol/package.json +++ b/indexers/warp-protocol/package.json @@ -16,7 +16,7 @@ "@aws-sdk/client-dynamodb": "^3.159.0", "@aws-sdk/util-dynamodb": "^3.159.0", "@terra-money/feather.js": "^1.0.11", - "@terra-money/warp-sdk": "0.1.71-rc12", + "@terra-money/warp-sdk": "^0.2.2", "@types/node": "^16.11.56", "axios": "^1.1.2", "big.js": "^6.2.1", diff --git a/yarn.lock b/yarn.lock index 87505c6f..e5b1b71d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4322,7 +4322,7 @@ __metadata: "@mui/material": ^5.10.2 "@terra-money/feather.js": ^1.0.11 "@terra-money/wallet-kit": ^1.0.11 - "@terra-money/warp-sdk": 0.1.71-rc12 + "@terra-money/warp-sdk": ^0.2.2 "@testing-library/jest-dom": ^5.16.5 "@testing-library/react": ^13.3.0 "@testing-library/user-event": ^13.5.0 @@ -4497,9 +4497,9 @@ __metadata: languageName: node linkType: hard -"@terra-money/warp-sdk@npm:0.1.71-rc12": - version: 0.1.71-rc12 - resolution: "@terra-money/warp-sdk@npm:0.1.71-rc12" +"@terra-money/warp-sdk@npm:^0.2.2": + version: 0.2.2 + resolution: "@terra-money/warp-sdk@npm:0.2.2" dependencies: "@terra-money/feather.js": ^1.0.11 "@types/node": ^16.11.56 @@ -4512,7 +4512,7 @@ __metadata: lodash: ^4.17.21 pino: ^8.4.2 typescript: ^4.8.2 - checksum: 2902336569783ffc0e9abfadbf6e9b3fbf5ced5d74cdbcea81aaa7013e3375c1235c4fc9a0cd04ee318e950eea72fb90648a39f93aece0f58a5f21a94b06c5f2 + checksum: b4a85a140fe728e87415d1d457d00860390be1f9cdb682698fbd174cd3926cdf29e97f32584f1b9b063bf3f5332155026af51d9d1bbc2b0db325dc0919676bab languageName: node linkType: hard @@ -5603,7 +5603,7 @@ __metadata: "@terra-money/feather.js": ^1.0.11 "@terra-money/terra-station-mobile": 1.0.8 "@terra-money/wallet-kit": ^1.0.11 - "@terra-money/warp-sdk": 0.1.71-rc12 + "@terra-money/warp-sdk": ^0.2.2 "@testing-library/jest-dom": ^5.16.5 "@testing-library/react": ^13.3.0 "@testing-library/user-event": ^13.5.0 @@ -5680,7 +5680,7 @@ __metadata: "@aws-sdk/client-dynamodb": ^3.159.0 "@aws-sdk/util-dynamodb": ^3.159.0 "@terra-money/feather.js": ^1.0.11 - "@terra-money/warp-sdk": 0.1.71-rc12 + "@terra-money/warp-sdk": ^0.2.2 "@types/d3-array": ^3.0.3 "@types/node": ^16.11.56 axios: ^1.1.2