Skip to content

Commit

Permalink
add : add disable input if isend or ibc transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
wseungjin committed Apr 23, 2021
1 parent 8309d4f commit 56b71dc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
30 changes: 27 additions & 3 deletions packages/mobile/src/modals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
useSignDocAmountConfig,
useSignDocHelper,
} from "@keplr-wallet/hooks";
import { Button, Input, Text } from "react-native-elements";
import { Input, Text } from "react-native-elements";
import {
flexDirectionRow,
justifyContentEnd,
Expand All @@ -23,6 +23,7 @@ import {
import { DefaultButton, WhiteButton } from "../components/buttons";
import { TransactionDetails } from "./transaction-details";
import { Page } from "../components/page";
import { useInteractionInfo } from "../hooks";

export const ModalsRenderer: FunctionComponent = observer(() => {
const {
Expand All @@ -33,6 +34,9 @@ export const ModalsRenderer: FunctionComponent = observer(() => {
keyRingStore,
signInteractionStore,
} = useStore();
const interactionInfo = useInteractionInfo(() => {
signInteractionStore.rejectAll();
});

const [password, setPassword] = useState("");

Expand All @@ -56,9 +60,24 @@ export const ModalsRenderer: FunctionComponent = observer(() => {
);
const memoConfig = useMemoConfig(chainStore, current.chainId);

const signDocWapper = signInteractionStore.waitingData?.data.signDocWrapper;
const signDocHelper = useSignDocHelper(feeConfig, memoConfig);
amountConfig.setSignDocHelper(signDocHelper);

const isSignDocInternalSend = (() => {
if (signDocWapper && signDocWapper.mode === "amino") {
const signDoc = signDocWapper.aminoSignDoc;
return (
interactionInfo.interaction &&
interactionInfo.interactionInternal &&
signDoc.msgs.length === 1 &&
(signDoc.msgs[0].type === "cosmos-sdk/MsgSend" ||
signDoc.msgs[0].type === "cosmos-sdk/MsgTransfer")
);
}
return false;
})();

useEffect(() => {
if (signInteractionStore.waitingData) {
const data = signInteractionStore.waitingData;
Expand All @@ -69,8 +88,12 @@ export const ModalsRenderer: FunctionComponent = observer(() => {
}
}, [gasConfig, memoConfig, signDocHelper, signInteractionStore.waitingData]);

feeConfig.setFeeType("average");
const [
isLoadingSignDocInternalSend,
setIsLoadingSignDocInternalSend,
] = useState(false);

const disableInputs = isSignDocInternalSend || isLoadingSignDocInternalSend;
return (
<React.Fragment>
<Modal
Expand All @@ -89,7 +112,7 @@ export const ModalsRenderer: FunctionComponent = observer(() => {
value={password}
onChangeText={setPassword}
/>
<Button
<DefaultButton
title="Unlock"
onPress={async () => {
await keyRingStore.unlock(password);
Expand All @@ -113,6 +136,7 @@ export const ModalsRenderer: FunctionComponent = observer(() => {
memoConfig={memoConfig}
feeConfig={feeConfig}
gasConfig={gasConfig}
disableInputs={disableInputs}
/>
<View style={flexDirectionRow}>
<WhiteButton
Expand Down
33 changes: 21 additions & 12 deletions packages/mobile/src/modals/transaction-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
px2,
} from "../styles";
import Icon from "react-native-vector-icons/Feather";
import { MemoInput, FeeButtons } from "../components/form";

export const TransactionDetails: FunctionComponent<{
signDocHelper: SignDocHelper;
Expand Down Expand Up @@ -97,18 +98,26 @@ export const TransactionDetails: FunctionComponent<{
<ScrollView style={sf([cardStyle, px2, mb2])}>
{renderedMsgs}
</ScrollView>
<View style={mb3}>
<Text style={sf([subtitle2, mb2])}>Memo</Text>
<Text style={subtitle1}>
{memoConfig.memo ? memoConfig.memo : "(No memo)"}
</Text>
</View>
<View style={mb3}>
<Text style={sf([subtitle2, mb2])}>Fee</Text>
<Text style={subtitle1}>
{feeConfig.fee.maxDecimals(6).trim(true).toString()}
</Text>
</View>
{!disableInputs ? (
<MemoInput memoConfig={memoConfig} />
) : (
<View style={mb3}>
<Text style={sf([subtitle2, mb2])}>Memo</Text>
<Text style={subtitle1}>
{memoConfig.memo ? memoConfig.memo : "(No memo)"}
</Text>
</View>
)}
{!disableInputs ? (
<FeeButtons feeConfig={feeConfig} priceStore={priceStore} />
) : (
<View style={mb3}>
<Text style={sf([subtitle2, mb2])}>Fee</Text>
<Text style={subtitle1}>
{feeConfig.fee.maxDecimals(6).trim(true).toString()}
</Text>
</View>
)}
</React.Fragment>
);
}
Expand Down

0 comments on commit 56b71dc

Please sign in to comment.