-
Notifications
You must be signed in to change notification settings - Fork 493
/
Copy pathindex.tsx
145 lines (137 loc) · 4.58 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import React, { FunctionComponent, useEffect, useState } from "react";
import { observer } from "mobx-react-lite";
import { useStore } from "../stores";
import Modal from "react-native-modal";
import { View } from "react-native";
import {
useFeeConfig,
useGasConfig,
useMemoConfig,
useSignDocAmountConfig,
useSignDocHelper,
} from "@keplr-wallet/hooks";
import { Button, Input, Text } from "react-native-elements";
import {
flexDirectionRow,
justifyContentEnd,
m0,
sf,
h4,
fAlignCenter,
my3,
} from "../styles";
import { DefaultButton, WhiteButton } from "../components/buttons";
import { TransactionDetails } from "./transaction-details";
import { Page } from "../components/page";
export const ModalsRenderer: FunctionComponent = observer(() => {
const {
chainStore,
accountStore,
queriesStore,
interactionModalStore,
keyRingStore,
signInteractionStore,
} = useStore();
const [password, setPassword] = useState("");
const [signer, setSigner] = useState("");
const current = chainStore.getChain(chainStore.current.chainId);
// Make the gas config with 1 gas initially to prevent the temporary 0 gas error at the beginning.
const gasConfig = useGasConfig(chainStore, current.chainId, 1);
const amountConfig = useSignDocAmountConfig(
chainStore,
current.chainId,
accountStore.getAccount(current.chainId).msgOpts
);
const feeConfig = useFeeConfig(
chainStore,
current.chainId,
signer,
queriesStore.get(current.chainId).getQueryBalances(),
amountConfig,
gasConfig
);
const memoConfig = useMemoConfig(chainStore, current.chainId);
const signDocHelper = useSignDocHelper(feeConfig, memoConfig);
amountConfig.setSignDocHelper(signDocHelper);
useEffect(() => {
if (signInteractionStore.waitingData) {
const data = signInteractionStore.waitingData;
signDocHelper.setSignDocWrapper(data.data.signDocWrapper);
gasConfig.setGas(data.data.signDocWrapper.gas);
memoConfig.setMemo(data.data.signDocWrapper.memo);
setSigner(data.data.signer);
}
}, [gasConfig, memoConfig, signDocHelper, signInteractionStore.waitingData]);
feeConfig.setFeeType("average");
return (
<React.Fragment>
<Modal
isVisible={interactionModalStore.lastUrl != null}
style={sf([justifyContentEnd, m0])}
>
<View style={{ height: 600 }}>
<Page>
{interactionModalStore.lastUrl === "/unlock" ? (
<React.Fragment>
<Text style={sf([h4, fAlignCenter, my3])}>Unlock</Text>
<Input
label="Password"
autoCompleteType="password"
secureTextEntry={true}
value={password}
onChangeText={setPassword}
/>
<Button
title="Unlock"
onPress={async () => {
await keyRingStore.unlock(password);
interactionModalStore.popUrl();
}}
/>
</React.Fragment>
) : null}
{interactionModalStore.lastUrl === "/sign" ? (
<React.Fragment>
<Text style={sf([h4, fAlignCenter, my3])}>
Confirm Transaction
</Text>
{/* <ScrollView>
<Text>
{JSON.stringify(signDocHelper.signDocJson, null, 2)}
</Text>
</ScrollView> */}
<TransactionDetails
signDocHelper={signDocHelper}
memoConfig={memoConfig}
feeConfig={feeConfig}
gasConfig={gasConfig}
/>
<View style={flexDirectionRow}>
<WhiteButton
title="Reject"
color="error"
onPress={async () => {
await signInteractionStore.reject();
interactionModalStore.popUrl();
}}
/>
<DefaultButton
title="Approve"
onPress={async () => {
if (signDocHelper.signDocWrapper) {
await signInteractionStore.approveAndWaitEnd(
signDocHelper.signDocWrapper
);
}
interactionModalStore.popUrl();
}}
/>
</View>
</React.Fragment>
) : null}
</Page>
</View>
</Modal>
</React.Fragment>
);
});