-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat: [GSW-684] Handle Wrapped GNOT
- Loading branch information
Showing
36 changed files
with
578 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/web/src/common/clients/wallet-client/adena/adena-client.util.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { SendTransactionResponse, WalletResponse } from "../protocols"; | ||
import { | ||
AdenaSendTransactionResponse, | ||
AdenaSendTransactionSuccessResponse, | ||
} from "./adena"; | ||
import {} from "@utils/rpc-utils"; | ||
|
||
function matchValues(str: string): string[] { | ||
const regexp = /\((.*)\)/g; | ||
const result = str.match(regexp); | ||
if (result === null || result.length < 1) { | ||
return []; | ||
} | ||
return result; | ||
} | ||
|
||
function parseABCIValue(str: string): string { | ||
const regexp = /\s.*$/; | ||
return str.replace(regexp, "").slice(1); | ||
} | ||
|
||
export function isTransactionSuccessResponse( | ||
walletResponse: WalletResponse<AdenaSendTransactionResponse>, | ||
): walletResponse is WalletResponse<AdenaSendTransactionSuccessResponse> { | ||
return walletResponse.status === "success"; | ||
} | ||
|
||
export function parseTransactionResponse( | ||
walletResponse: WalletResponse<AdenaSendTransactionResponse>, | ||
): WalletResponse<SendTransactionResponse<string | null>> { | ||
if (!isTransactionSuccessResponse(walletResponse)) { | ||
return { | ||
...walletResponse, | ||
data: { | ||
hash: "", | ||
height: "", | ||
data: null, | ||
}, | ||
} as WalletResponse<SendTransactionResponse<string | null>>; | ||
} | ||
|
||
let data: string | null = null; | ||
const encodedData = walletResponse.data?.deliver_tx.ResponseBase.Data || null; | ||
if (encodedData) { | ||
const decodedData = window.atob(encodedData); | ||
try { | ||
const result = matchValues(decodedData); | ||
data = parseABCIValue(result[0]); | ||
} catch { | ||
data = null; | ||
} | ||
} | ||
return { | ||
code: walletResponse.code, | ||
status: walletResponse.status, | ||
type: walletResponse.type, | ||
message: walletResponse.message, | ||
data: { | ||
hash: walletResponse.data?.hash || "", | ||
height: walletResponse.data?.height || "", | ||
data, | ||
}, | ||
} as WalletResponse<SendTransactionResponse<string | null>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/web/src/common/clients/wallet-client/transaction-messages/common.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
export const PACKAGE_ROUTER_PATH = | ||
process.env.NEXT_PUBLIC_PACKAGE_ROUTER_PATH || ""; | ||
export const PACKAGE_POOL_PATH = | ||
process.env.NEXT_PUBLIC_PACKAGE_POOL_PATH || ""; | ||
export const PACKAGE_POSITION_PATH = | ||
process.env.NEXT_PUBLIC_PACKAGE_POSITION_PATH || ""; | ||
export const PACKAGE_STAKER_PATH = | ||
process.env.NEXT_PUBLIC_PACKAGE_STAKER_PATH || ""; | ||
export const PACKAGE_NFT_PATH = process.env.NEXT_PUBLIC_PACKAGE_NFT_PATH || ""; | ||
export const GOVERNANCE_PATH = process.env.NEXT_PUBLIC_GOVERNANCE_PATH || ""; | ||
export const WRAPPED_GNOT_PATH = | ||
process.env.NEXT_PUBLIC_WRAPPED_GNOT_PATH || ""; | ||
export const PACKAGE_ROUTER_ADDRESS = | ||
process.env.NEXT_PUBLIC_PACKAGE_ROUTER_ADDRESS || ""; | ||
export const PACKAGE_POOL_ADDRESS = | ||
process.env.NEXT_PUBLIC_PACKAGE_POOL_ADDRESS || ""; | ||
export const PACKAGE_POSITION_ADDRESS = | ||
process.env.NEXT_PUBLIC_PACKAGE_POSITION_ADDRESS || ""; | ||
export const PACKAGE_STAKER_ADDRESS = | ||
process.env.NEXT_PUBLIC_PACKAGE_STAKER_ADDRESS || ""; | ||
export const PACKAGE_GOVERNANCE_ADDRESS = | ||
process.env.NEXT_PUBLIC_PACKAGE_GOVERNANCE_ADDRESS || ""; | ||
|
||
export interface TransactionMessage { | ||
caller: string; | ||
send: string; | ||
pkg_path: string; | ||
func: string; | ||
args: string[] | null; | ||
} | ||
|
||
export function makeTransactionMessage({ | ||
caller, | ||
send, | ||
packagePath, | ||
func, | ||
args, | ||
}: { | ||
caller: string; | ||
send: string; | ||
packagePath: string; | ||
func: string; | ||
args: string[] | null; | ||
}): TransactionMessage { | ||
return { | ||
caller: caller, | ||
send: send, | ||
pkg_path: packagePath, | ||
func: func, | ||
args: args, | ||
}; | ||
} | ||
|
||
export function makeApproveMessage( | ||
packagePath: string, | ||
args: string[], | ||
caller: string, | ||
) { | ||
return makeTransactionMessage({ | ||
caller, | ||
send: "", | ||
packagePath, | ||
func: "Approve", | ||
args, | ||
}); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/web/src/common/clients/wallet-client/transaction-messages/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./common"; |
13 changes: 13 additions & 0 deletions
13
packages/web/src/common/clients/wallet-client/transaction-messages/pool.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { makeApproveMessage, PACKAGE_POOL_ADDRESS } from "./common"; | ||
|
||
export function makePoolTokenApproveMessage( | ||
packagePath: string, | ||
amount: string, | ||
caller: string, | ||
) { | ||
return makeApproveMessage( | ||
packagePath, | ||
[PACKAGE_POOL_ADDRESS, amount], | ||
caller, | ||
); | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/web/src/common/clients/wallet-client/transaction-messages/token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { makeTransactionMessage } from "./common"; | ||
|
||
export function makeDepositMessage( | ||
packagePath: string, | ||
amount: string, | ||
denom: string, | ||
caller: string, | ||
) { | ||
const send = `${amount.toString()}${denom}`; | ||
return makeTransactionMessage({ | ||
packagePath, | ||
send, | ||
func: "Deposit", | ||
args: null, | ||
caller, | ||
}); | ||
} | ||
|
||
export function makeWithdrawMessage( | ||
packagePath: string, | ||
amount: string, | ||
caller: string, | ||
) { | ||
return makeTransactionMessage({ | ||
packagePath, | ||
send: "", | ||
func: "Withdraw", | ||
args: [amount.toString()], | ||
caller, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.