Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix kujira factory IBC tokens #466

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/data/queries/ibc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export const useIBCBaseDenoms = (data: { denom: Denom; chainID: string }[]) => {
ibcDenom: denom,
baseDenom: base_denom.startsWith("cw20:")
? base_denom.replace("cw20:", "")
: // fix for kujira factory tokens
base_denom.startsWith("factory:")
? base_denom.replaceAll(":", "/")
: base_denom,
chainIDs: chains,
channels,
Expand All @@ -110,7 +113,10 @@ export const useIBCBaseDenoms = (data: { denom: Denom; chainID: string }[]) => {
}

export function calculateIBCDenom(baseDenom: string, path: string) {
if (!path) return baseDenom
if (!path)
return baseDenom.startsWith("factory:")
? baseDenom.replaceAll(":", "/")
: baseDenom

const assetString = [
path,
Expand Down
13 changes: 10 additions & 3 deletions src/pages/wallet/IbcSendBackTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function IbcSendBackTx({ token, chainID }: Props) {
const { errors } = formState
const { input } = watch()
const queryClient = useQueryClient()
const networks = useNetwork()

const [step, setStep] = useState<number>(0)
const [isLoading, setIsLoading] = useState<boolean>(false)
Expand Down Expand Up @@ -122,6 +123,8 @@ function IbcSendBackTx({ token, chainID }: Props) {
}
}

const isKujira = networks[ibcDetails?.chainIDs[0] ?? ""]?.prefix === "kujira"

useEffect(() => {
// around 3 minutes with a 10 seconds interval
let maxIterations = 18
Expand Down Expand Up @@ -160,7 +163,9 @@ function IbcSendBackTx({ token, chainID }: Props) {
() =>
ibcDetails &&
calculateIBCDenom(
ibcDetails.baseDenom,
isKujira
? ibcDetails.baseDenom?.replaceAll("/", ":")
: ibcDetails.baseDenom,
ibcDetails.channels
.slice(0, ibcDetails.channels.length - step)
.reduce(
Expand All @@ -171,7 +176,7 @@ function IbcSendBackTx({ token, chainID }: Props) {
""
)
),
[step, ibcDetails]
[step, ibcDetails, isKujira]
)

const chains = useMemo(
Expand Down Expand Up @@ -234,7 +239,9 @@ function IbcSendBackTx({ token, chainID }: Props) {
onChangeMax,
onPost: () => {
const nextDenom = calculateIBCDenom(
ibcDetails?.baseDenom ?? "",
(isKujira
? ibcDetails?.baseDenom?.replaceAll("/", ":")
: ibcDetails?.baseDenom) ?? "",
(ibcDetails?.channels ?? [])
.slice(0, (ibcDetails?.channels.length ?? 0) - step - 1)
.reduce(
Expand Down