Skip to content

Commit

Permalink
fix get relayer fee
Browse files Browse the repository at this point in the history
  • Loading branch information
perfogic committed Aug 21, 2024
1 parent 298663e commit 30b17f0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
31 changes: 21 additions & 10 deletions components/page/bridge/hooks/useGetFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,31 @@ const useGetFee = ({ token }: { token: TokenType }) => {

useEffect(() => {
(async () => {
const tonBridgeClient = new TonbridgeBridgeClient(
window.client,
oraiAddress,
network.CW_TON_BRIDGE
);
if (token) {
const tokenInTon = TonTokenList(TonNetwork.Mainnet).find(
(tk) => tk.coingeckoId === token.coingeckoId
);
if (!tokenInTon) {
return;
}

const tonBridgeClient = new TonbridgeBridgeClient(
window.client,
oraiAddress,
network.CW_TON_BRIDGE
);

const config = await tonBridgeClient.config();
if (config) {
const { relayer_fee } = config;
const config = await tonBridgeClient.pairMapping({
key: tokenInTon?.contractAddress,
});
const pairMapping = config.pair_mapping;

setBridgeFee(toDisplay(relayer_fee));
setBridgeFee(
parseInt(pairMapping.relayer_fee) / 10 ** pairMapping.remote_decimals
);
}
})();
}, []);
}, [token, oraiAddress]);

return {
bridgeFee,
Expand Down
3 changes: 2 additions & 1 deletion components/page/bridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const Bridge = () => {
? oraiAddress || ""
: tonAddress || "";

console.log("Read token:", { token });
const { bridgeFee, tokenFee } = useGetFee({
token,
});
Expand Down Expand Up @@ -618,7 +619,7 @@ const Bridge = () => {
{numberWithCommas(bridgeFee || 0, undefined, {
maximumFractionDigits: CW20_DECIMALS,
})}{" "}
ORAI
{token?.symbol}
</span>
</div>
<div className={styles.itemEst}>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@oraichain/orai-bitcoin": "^2.0.0",
"@oraichain/oraidex-common": "^1.0.88-beta.1",
"@oraichain/ton-bridge-contracts": "^0.15.5",
"@oraichain/tonbridge-contracts-sdk": "1.3.0",
"@oraichain/tonbridge-contracts-sdk": "^1.3.1",
"@orbs-network/ton-access": "^2.3.3",
"@tanstack/react-query": "^5.49.2",
"@ton/core": "~0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1624,10 +1624,10 @@
dotenv "^16.4.5"
varstruct "^6.1.3"

"@oraichain/[email protected].0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@oraichain/tonbridge-contracts-sdk/-/tonbridge-contracts-sdk-1.3.0.tgz#b03f28005722604fe4d557dd8e58ef214ade5874"
integrity sha512-yTGlH5Oyq6s3cj63EJoBx+n4YxqhN6EcC8I0h9HmlOnGxzZgLY3AUkFjkFPgn5prH9dIfixhXnfh/TPXq0j9Pw==
"@oraichain/tonbridge-contracts-sdk@^1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@oraichain/tonbridge-contracts-sdk/-/tonbridge-contracts-sdk-1.3.1.tgz#5c2981b5c1c99bda7db143d8f294449bdc15f2d7"
integrity sha512-atSmGRzlGodjidY32I50UJPtVIriaoeqOOw/Qx2qnCk2S/1z5oAotPO9mfHeLALb3rgN/gtXhtQj/dqCU0rlsA==

"@orbs-network/ton-access@^2.3.3":
version "2.3.3"
Expand Down

0 comments on commit 30b17f0

Please sign in to comment.