master
icechen 2022-02-17 04:21:21 +08:00
parent a1cd6cc89a
commit 65ac000169
1 changed files with 35 additions and 12 deletions

View File

@ -3,36 +3,59 @@ import "./App.css";
import Client from "mtproton/envs/browser";
function App() {
let [countriesList, setcountriesList] = useState([]);
let [countriesList, setcountriesList] = useState([] as any[]);
let phone = React.createRef<HTMLInputElement>();
useEffect(() => {
let client = new Client({
api_id: 18987971,
api_hash: "fcfd9e6ed3f9e48a360bb57cc0d59d98",
});
client.call("help.getCountriesList").then((result: any) => {
console.log("country:", result);
let resp: any[] = [];
result.countries.map((country: any) => {
// @ts-ignore
setcountriesList((oldArray) => [
...oldArray,
country.default_name + ": " + country.country_codes[0].country_code,
]);
resp.push(
country.default_name + ": " + country.country_codes[0].country_code
);
return true;
});
setcountriesList(resp);
});
}, []);
// client
// .invoke({
// _: "getCountryCode",
// })
// .then((res) => {
// console.log(res);
// });
let sendCode = () => {
console.log("phone:", phone.current?.value);
let client = new Client({
api_id: 18987971,
api_hash: "fcfd9e6ed3f9e48a360bb57cc0d59d98",
});
client.setDefaultDc(5);
client
.call("auth.sendCode", {
phone_number: phone.current?.value,
settings: {
_: "codeSettings",
},
})
.then((result: any) => {
console.log("auth.sendCode:", result);
})
.catch((error: any) => {
console.log("auth.sendCode:", error);
});
};
let login = () => {};
return (
<div className="App">
<input ref={phone} />
<button onClick={sendCode}></button>
<input />
<button onClick={login}></button>
{countriesList.map((country: any, index) => {
return (
<div key={index}>