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