Skip to content

Commit

Permalink
Merge branch 'delivan/keplr-486' into Thunnini/prepare-starknet
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunnini committed Oct 8, 2024
2 parents bab6c77 + c19376a commit 52bb87e
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 208 deletions.
46 changes: 24 additions & 22 deletions apps/extension/src/pages/main/token-detail/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -673,30 +673,32 @@ export const TokenDetailModal: FunctionComponent<{

if (msgHistory.pages[0].response?.isUnsupported || !isSupported) {
// TODO: 아직 cosmos 체인이 아니면 embedded인지 아닌지 구분할 수 없다.
if ("cosmos" in modularChainInfo) {
const chainInfo = chainStore.getChain(chainId);
if (chainInfo.embedded.embedded) {
return (
<EmptyView>
<Box marginX="2rem">
<Stack alignX="center" gutter="0.1rem">
<Subtitle3 style={{ fontWeight: 700 }}>
Unsupported Chain
</Subtitle3>
<Subtitle3
style={{
textAlign: "center",
}}
>
{`We're actively working on expanding our support for
if (
("cosmos" in modularChainInfo &&
chainStore.getChain(chainId).embedded.embedded) ||
"starknet" in modularChainInfo
) {
return (
<EmptyView>
<Box marginX="2rem">
<Stack alignX="center" gutter="0.1rem">
<Subtitle3 style={{ fontWeight: 700 }}>
Unsupported Chain
</Subtitle3>
<Subtitle3
style={{
textAlign: "center",
}}
>
{`We're actively working on expanding our support for
native chains.`}
</Subtitle3>
</Stack>
</Box>
</EmptyView>
);
}
</Subtitle3>
</Stack>
</Box>
</EmptyView>
);
}

return (
<EmptyView>
<Box marginX="2rem">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const AccountActivationModal: FunctionComponent<{

const intl = useIntl();
const account = accountStore.getAccount(chainId);
const starknetQueries = starknetQueriesStore.get(chainId);

const sender = account.starknetHexAddress;
const senderConfig = useSenderConfig(
Expand Down Expand Up @@ -102,6 +103,22 @@ export const AccountActivationModal: FunctionComponent<{
return () => clearInterval(interval);
}, [gasSimulationRefresher]);

useEffect(() => {
starknetQueries.queryAccountNonce
.getNonce(account.starknetHexAddress)
.fetch();
if (feeConfig.fee != null) {
starknetQueries.queryStarknetERC20Balance
.getBalance(
chainId,
chainStore,
account.starknetHexAddress,
feeConfig.fee.currency.coinMinimalDenom
)
?.fetch();
}
}, []);

const gasSimulatorKey = feeConfig.type;
const gasSimulator = useGasSimulator(
new ExtensionKVStore("gas-simulator.starknet.account-activation"),
Expand Down Expand Up @@ -283,39 +300,38 @@ export const AccountActivationModal: FunctionComponent<{
throw new Error("Can't find fee currency");
}

starknetAccount.setIsDeployingAccount(true);
const { transaction_hash: txHash } =
await starknetAccountStore
.getAccount(senderConfig.chainId)
.deployAccountWithFee(
accountStore.getAccount(senderConfig.chainId)
.starknetHexAddress,
"0x" + Buffer.from(params.classHash).toString("hex"),
[
"0x" + Buffer.from(params.xLow).toString("hex"),
"0x" + Buffer.from(params.xHigh).toString("hex"),
"0x" + Buffer.from(params.yLow).toString("hex"),
"0x" + Buffer.from(params.yHigh).toString("hex"),
],
"0x" + Buffer.from(params.salt).toString("hex"),
(() => {
if (type === "ETH") {
return {
type: "ETH",
maxFee: feeConfig.maxFee.toCoin().amount,
};
} else if (type === "STRK") {
return {
type: "STRK",
gas: gasConfig.gas.toString(),
maxGasPrice: num.toHex(
feeConfig.maxGasPrice.toCoin().amount
),
};
} else {
throw new Error("Invalid fee type");
}
})()
);
await starknetAccount.deployAccountWithFee(
accountStore.getAccount(senderConfig.chainId)
.starknetHexAddress,
"0x" + Buffer.from(params.classHash).toString("hex"),
[
"0x" + Buffer.from(params.xLow).toString("hex"),
"0x" + Buffer.from(params.xHigh).toString("hex"),
"0x" + Buffer.from(params.yLow).toString("hex"),
"0x" + Buffer.from(params.yHigh).toString("hex"),
],
"0x" + Buffer.from(params.salt).toString("hex"),
(() => {
if (type === "ETH") {
return {
type: "ETH",
maxFee: feeConfig.maxFee.toCoin().amount,
};
} else if (type === "STRK") {
return {
type: "STRK",
gas: gasConfig.gas.toString(),
maxGasPrice: num.toHex(
feeConfig.maxGasPrice.toCoin().amount
),
};
} else {
throw new Error("Invalid fee type");
}
})()
);

new InExtensionMessageRequester()
.sendMessage(
Expand All @@ -330,7 +346,6 @@ export const AccountActivationModal: FunctionComponent<{
}),
""
);

const starknetQueries =
starknetQueriesStore.get(chainId);

Expand All @@ -343,6 +358,19 @@ export const AccountActivationModal: FunctionComponent<{
.getNonce(account.starknetHexAddress)
.waitFreshResponse();
if (res?.data) {
starknetAccount.setIsDeployingAccount(false);

Check failure on line 362 in apps/extension/src/pages/starknet/components/account-activation-modal/index.tsx

View workflow job for this annotation

GitHub Actions / Lint code base

Delete `·····························`
if (feeConfig.fee != null) {
starknetQueries.queryStarknetERC20Balance
.getBalance(
chainId,
chainStore,
account.starknetHexAddress,
feeConfig.fee.currency.coinMinimalDenom
)
?.fetch();
}
close();
break;
}

Expand All @@ -351,26 +379,15 @@ export const AccountActivationModal: FunctionComponent<{
await sleep(2000);
}
})();

if (feeConfig.fee != null) {
starknetQueries.queryStarknetERC20Balance
.getBalance(
chainId,
chainStore,
account.starknetHexAddress,
feeConfig.fee.currency.coinMinimalDenom
)
?.fetch();
}

close();
})
.catch((e) => {
// 이 경우에는 tx가 커밋된 이후의 오류이기 때문에 이미 페이지는 sign 페이지에서부터 전환된 상태다.
// 따로 멀 처리해줄 필요가 없다
starknetAccount.setIsDeployingAccount(false);
close();
console.log(e);
});
} catch (e) {
starknetAccount.setIsDeployingAccount(false);
goBack();
console.log(e);
}
}
Expand Down
Loading

0 comments on commit 52bb87e

Please sign in to comment.