[WIP] Simulate
This commit is contained in:
parent
febde1e7c4
commit
8504c84d3c
@ -52,7 +52,7 @@ export const AllChainsItem: FunctionComponent<Props> = (props) => {
|
|||||||
|
|
||||||
<Flex1 />
|
<Flex1 />
|
||||||
|
|
||||||
<ChainCheckBox checked={allChecked} />
|
<ChainCheckBox checked={allChecked} readOnly />
|
||||||
</ChainItemContainer>
|
</ChainItemContainer>
|
||||||
</AllChainsContainer>
|
</AllChainsContainer>
|
||||||
);
|
);
|
||||||
|
@ -41,6 +41,7 @@ export const ChainItem: FunctionComponent<Props> = (props) => {
|
|||||||
<ChainItemContainer
|
<ChainItemContainer
|
||||||
key={chainItem.prefix}
|
key={chainItem.prefix}
|
||||||
isLoading={false}
|
isLoading={false}
|
||||||
|
checked={checked}
|
||||||
onClick={checkHandler}
|
onClick={checkHandler}
|
||||||
>
|
>
|
||||||
<ChainImageContainer width="3rem" height="3rem">
|
<ChainImageContainer width="3rem" height="3rem">
|
||||||
@ -57,7 +58,7 @@ export const ChainItem: FunctionComponent<Props> = (props) => {
|
|||||||
|
|
||||||
<Flex1 />
|
<Flex1 />
|
||||||
|
|
||||||
<ChainCheckBox checked={checked} />
|
<ChainCheckBox checked={checked} readOnly />
|
||||||
</ChainItemContainer>
|
</ChainItemContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -73,7 +73,10 @@ export const ChainContainer = styled.div`
|
|||||||
background-color: ${(props) => props.color};
|
background-color: ${(props) => props.color};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const ChainItemContainer = styled.div<{ isLoading: boolean }>`
|
export const ChainItemContainer = styled.div<{
|
||||||
|
isLoading: boolean;
|
||||||
|
checked?: boolean;
|
||||||
|
}>`
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
7
constants/icns.ts
Normal file
7
constants/icns.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export const RPC_URL = "";
|
||||||
|
export const REST_URL = "https://lcd.testnet.osmosis.zone";
|
||||||
|
|
||||||
|
export const REGISTRAR_ADDRESS =
|
||||||
|
"osmo1npn97g7hsgqlp70rw8nhd7c7vyvkukv9x0n25sn4fk5mgcjlz4gq9zlgf3";
|
||||||
|
export const RESOLVER_ADDRESS =
|
||||||
|
"osmo1002awr7frr9wk44lc3vfzt0d2w6vz5z03ql6fszjsjy8vdcvk0sskruz3c";
|
@ -22,12 +22,22 @@ import { TwitterProfile } from "../../components/twitter-profile";
|
|||||||
import { ChainList } from "../../components/chain-list";
|
import { ChainList } from "../../components/chain-list";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { MainChainId } from "../../constants/wallet";
|
import { MainChainId } from "../../constants/wallet";
|
||||||
import { getKeplrFromWindow, KeplrWallet } from "../../wallets";
|
import {
|
||||||
|
getKeplrFromWindow,
|
||||||
|
KeplrWallet,
|
||||||
|
makeCosmwasmExecMsg,
|
||||||
|
simulateMsgs,
|
||||||
|
} from "../../wallets";
|
||||||
import { ChainIdHelper } from "@keplr-wallet/cosmos";
|
import { ChainIdHelper } from "@keplr-wallet/cosmos";
|
||||||
|
|
||||||
import AllChainsIcon from "../../public/images/svg/all-chains-icon.svg";
|
import AllChainsIcon from "../../public/images/svg/all-chains-icon.svg";
|
||||||
import { AllChainsItem } from "../../components/chain-list/all-chains-item";
|
import { AllChainsItem } from "../../components/chain-list/all-chains-item";
|
||||||
import { SearchInput } from "../../components/search-input";
|
import { SearchInput } from "../../components/search-input";
|
||||||
|
import {
|
||||||
|
REGISTRAR_ADDRESS,
|
||||||
|
RESOLVER_ADDRESS,
|
||||||
|
REST_URL,
|
||||||
|
} from "../../constants/icns";
|
||||||
|
|
||||||
export default function VerificationPage() {
|
export default function VerificationPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@ -51,7 +61,8 @@ export default function VerificationPage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await fetchTwitterInfo();
|
const twitterInfo = await fetchTwitterInfo();
|
||||||
|
setTwitterAuthInfo(twitterInfo);
|
||||||
|
|
||||||
await initWallet();
|
await initWallet();
|
||||||
|
|
||||||
@ -62,7 +73,7 @@ export default function VerificationPage() {
|
|||||||
handleVerification();
|
handleVerification();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const fetchTwitterInfo = async () => {
|
const fetchTwitterInfo = async (): Promise<TwitterAuthInfoResponse> => {
|
||||||
const [, state, code] =
|
const [, state, code] =
|
||||||
window.location.search.match(
|
window.location.search.match(
|
||||||
/^(?=.*state=([^&]+)|)(?=.*code=([^&]+)|).+$/,
|
/^(?=.*state=([^&]+)|)(?=.*code=([^&]+)|).+$/,
|
||||||
@ -72,7 +83,7 @@ export default function VerificationPage() {
|
|||||||
`/api/twitter-auth-info?state=${state}&code=${code}`,
|
`/api/twitter-auth-info?state=${state}&code=${code}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
setTwitterAuthInfo(newTwitterAuthInfo);
|
return newTwitterAuthInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
const initWallet = async () => {
|
const initWallet = async () => {
|
||||||
@ -144,8 +155,8 @@ export default function VerificationPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const verifyTwitterAccount = async () => {
|
const verifyTwitterAccount = async (accessToken: string) => {
|
||||||
if (twitterAuthInfo && wallet) {
|
if (wallet) {
|
||||||
const key = await wallet.getKey(MainChainId);
|
const key = await wallet.getKey(MainChainId);
|
||||||
|
|
||||||
const icnsVerificationList = (
|
const icnsVerificationList = (
|
||||||
@ -156,19 +167,121 @@ export default function VerificationPage() {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
claimer: key.bech32Address,
|
claimer: key.bech32Address,
|
||||||
authToken: twitterAuthInfo.accessToken,
|
authToken: accessToken,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
).verificationList;
|
).verificationList;
|
||||||
|
|
||||||
console.log(icnsVerificationList);
|
return icnsVerificationList;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkAdr36 = async () => {
|
||||||
|
if (twitterAuthInfo && wallet) {
|
||||||
|
const key = await wallet.getKey(MainChainId);
|
||||||
|
|
||||||
|
const chainIds = Array.from(checkedItems).map(
|
||||||
|
(chain) => (chain as ChainItemType).chainId,
|
||||||
|
);
|
||||||
|
|
||||||
|
const adr36Infos = await wallet.signICNSAdr36(
|
||||||
|
MainChainId,
|
||||||
|
RESOLVER_ADDRESS,
|
||||||
|
key.bech32Address,
|
||||||
|
twitterAuthInfo.username,
|
||||||
|
chainIds,
|
||||||
|
);
|
||||||
|
|
||||||
|
return adr36Infos;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onClickRegistration = async () => {
|
const onClickRegistration = async () => {
|
||||||
await verifyTwitterAccount();
|
const adr36Infos = await checkAdr36();
|
||||||
|
|
||||||
await router.push("/complete");
|
const twitterInfo = await fetchTwitterInfo();
|
||||||
|
|
||||||
|
const icnsVerificationList = await verifyTwitterAccount(
|
||||||
|
twitterInfo.accessToken,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (wallet && icnsVerificationList && adr36Infos) {
|
||||||
|
const key = await wallet.getKey(MainChainId);
|
||||||
|
|
||||||
|
const registerMsg = makeCosmwasmExecMsg(
|
||||||
|
key.bech32Address,
|
||||||
|
REGISTRAR_ADDRESS,
|
||||||
|
{
|
||||||
|
claim: {
|
||||||
|
name: twitterInfo.username,
|
||||||
|
verifying_msg:
|
||||||
|
icnsVerificationList[0].status === "fulfilled"
|
||||||
|
? icnsVerificationList[0].value.data.verifying_msg
|
||||||
|
: "",
|
||||||
|
verifications: icnsVerificationList.map((verification) => {
|
||||||
|
if (verification.status === "fulfilled") {
|
||||||
|
return {
|
||||||
|
public_key: verification.value.data.public_key,
|
||||||
|
signature: verification.value.data.signature,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[
|
||||||
|
{
|
||||||
|
denom: "uosmo",
|
||||||
|
amount: "500000",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
const addressMsgs = adr36Infos.map((adr36Info) => {
|
||||||
|
return makeCosmwasmExecMsg(
|
||||||
|
key.bech32Address,
|
||||||
|
RESOLVER_ADDRESS,
|
||||||
|
{
|
||||||
|
set_record: {
|
||||||
|
name: twitterInfo.username,
|
||||||
|
bech32_prefix: adr36Info.bech32Prefix,
|
||||||
|
adr36_info: {
|
||||||
|
signer_bech32_address: adr36Info.bech32Address,
|
||||||
|
address_hash: adr36Info.addressHash,
|
||||||
|
pub_key: Buffer.from(adr36Info.pubKey).toString("base64"),
|
||||||
|
signature: Buffer.from(adr36Info.signature).toString("base64"),
|
||||||
|
signature_salt: adr36Info.signatureSalt.toString(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const aminoMsgs = [registerMsg.amino];
|
||||||
|
const protoMsgs = [registerMsg.proto];
|
||||||
|
for (const addressMsg of addressMsgs) {
|
||||||
|
aminoMsgs.push(addressMsg.amino);
|
||||||
|
protoMsgs.push(addressMsg.proto);
|
||||||
|
}
|
||||||
|
|
||||||
|
const chainInfo = {
|
||||||
|
chainId: MainChainId,
|
||||||
|
rest: REST_URL,
|
||||||
|
};
|
||||||
|
|
||||||
|
const simulated = await simulateMsgs(
|
||||||
|
chainInfo,
|
||||||
|
key.bech32Address,
|
||||||
|
{
|
||||||
|
proto: protoMsgs,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
amount: [],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("simulated", simulated);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user