From ef7f0815d0cdb7ae3be531cdc78c22d54a559565 Mon Sep 17 00:00:00 2001 From: LiangShuang Date: Thu, 4 May 2023 16:41:13 +0800 Subject: [PATCH 001/167] fix cache delete issue --- packages/pawket-chia-lib/services/api/debug.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/pawket-chia-lib/services/api/debug.ts b/packages/pawket-chia-lib/services/api/debug.ts index 2e135e3c..c4d9c34c 100644 --- a/packages/pawket-chia-lib/services/api/debug.ts +++ b/packages/pawket-chia-lib/services/api/debug.ts @@ -27,7 +27,9 @@ class DebugApi { const presp = await response.json() as GetCoinSolutionResponse; const cs = presp.coinSpends?.at(0); if (!cs) { - await caches.delete(key); + caches.open("debug").then((cache) => { + cache.delete(key); + }); throw new Error("abnormal response"); } return cs; From 1e673d01b9a0cc393a15c833221ed9bd1710fdc2 Mon Sep 17 00:00:00 2001 From: LiangShuang Date: Thu, 4 May 2023 17:13:15 +0800 Subject: [PATCH 002/167] allow configurable external rpc url --- package.json | 2 +- packages/cli/app.ts | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 245c7c7c..1aa04a8e 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "serve:mixch": "cd ./packages/pawket && cross-env VUE_CLI_SERVICE_CONFIG_PATH=vue.config.mixch.js vue-cli-service serve --port 8088", "check-i18n": "vue-i18n-extract report --vueFiles \"./packages/pawket/src/**/*.?(js|ts|vue)\" --languageFiles \"./packages/pawket/src/i18n/?(en|zh-cn).?(json|yml|yaml|js)\"", "check-i18n:all": "vue-i18n-extract report --vueFiles \"./packages/pawket/src/**/*.?(js|ts|vue)\" --languageFiles \"./packages/pawket/src/i18n/*.?(json|yml|yaml|js)\"", - "serve:server": "nodemon cli/server.ts", + "serve:server": "cd ./packages/cli && nodemon server.ts", "start": "cross-env MAX_THREAD=0 ts-node cli/server.ts", "importmods": "cd ./packages/cli && ts-node importmods.ts", "compile": "ts-node cli/compile.ts", diff --git a/packages/cli/app.ts b/packages/cli/app.ts index 65bfd62a..dae104a7 100644 --- a/packages/cli/app.ts +++ b/packages/cli/app.ts @@ -26,7 +26,7 @@ global.fetch = fetch const app: express.Express = express() app.use(express.json({ limit: '3mb' })) app.use(express.urlencoded({ extended: true })) -const rpcUrl = "https://walletapi.chiabee.net/"; +const defaultRpcUrl = "https://walletapi.chiabee.net/"; interface ParseBlockRequest { ref_list?: string[], @@ -58,11 +58,12 @@ interface CnsOfferRequest { puzzleText: string; royaltyAddress: string; royaltyPercentage: number; - chainId: string; - symbol: string; - prefix: string; + chainId?: string; + symbol?: string; + prefix?: string; nonce?: string;//test only intermediateKey?: string;//test only + rpcUrl?: string; } interface TransferTargetOrigin { @@ -81,6 +82,7 @@ interface BatchSendRequest { symbol?: string; prefix?: string; availcoins?: SymbolCoins; + rpcUrl?: string; } interface PuzzleRequest { @@ -170,6 +172,7 @@ Instance.init().then(() => { r.chainId = r.chainId || "ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb"; r.prefix = r.prefix || "xch"; r.symbol = r.symbol || "XCH"; + const rpcUrl = r.rpcUrl || defaultRpcUrl; const sk = Instance.BLS?.PrivateKey.from_bytes(utility.fromHexString(r.privateKey), false); if (!sk) { @@ -257,6 +260,7 @@ Instance.init().then(() => { r.chainId = r.chainId || "ccd5bb71183532bff220ba46c268991a3ff07eb358e8255a65c30a2dce0e5fbb"; r.prefix = r.prefix || "xch"; r.symbol = r.symbol || "XCH"; + const rpcUrl = r.rpcUrl || defaultRpcUrl; if (r.metadata.bindings.address?.startsWith("xch1")) r.metadata.bindings.address = puzzle.getPuzzleHashFromAddress(r.metadata.bindings.address); const availcoinsForMaker: SymbolCoins = { @@ -293,7 +297,7 @@ Instance.init().then(() => { chainId: r.chainId, prefix: r.prefix, symbol: r.symbol, - api: (_) => getLineageProofPuzzle(_, "https://walletapi.chiabee.net/"), + api: (_) => getLineageProofPuzzle(_, rpcUrl), }; const uofferBundle = await generateMintCnsOffer( r.targetAddress, From da51cdf57782afec298ac937782796bc07bcef48 Mon Sep 17 00:00:00 2001 From: LiangShuang Date: Sat, 15 Jul 2023 10:37:14 +0800 Subject: [PATCH 003/167] fix version --- .github/workflows/build-pawket.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-pawket.yml b/.github/workflows/build-pawket.yml index badb3dee..303262e3 100644 --- a/.github/workflows/build-pawket.yml +++ b/.github/workflows/build-pawket.yml @@ -28,7 +28,7 @@ jobs: - name: Install Dependencies run: | - sed -i 's/0.0.0.0/${VERSION}/' packages/pawket/.env.production + sed -i "s/0.0.0.0/${VERSION}/" packages/pawket/.env.production - name: Build pawket run: | yarn build:pawket From 674c3c2bcd2c810d23d8a1c027e9bd2ad34ef921 Mon Sep 17 00:00:00 2001 From: LiangShuang Date: Tue, 18 Jul 2023 16:27:08 +0800 Subject: [PATCH 004/167] disable usds and init swap --- .../src/components/Home/AccountDetail.vue | 30 +- .../Swap/SimplifiedTokenAmountField.vue | 157 ++++++++ .../pawket/src/components/Swap/SwapPage.vue | 349 ++++++++++++++++++ packages/pawket/src/i18n/en.json | 1 + packages/pawket/src/router/index.ts | 4 + 5 files changed, 540 insertions(+), 1 deletion(-) create mode 100644 packages/pawket/src/components/Swap/SimplifiedTokenAmountField.vue create mode 100644 packages/pawket/src/components/Swap/SwapPage.vue diff --git a/packages/pawket/src/components/Home/AccountDetail.vue b/packages/pawket/src/components/Home/AccountDetail.vue index 36ce6a22..00f1f76a 100644 --- a/packages/pawket/src/components/Home/AccountDetail.vue +++ b/packages/pawket/src/components/Home/AccountDetail.vue @@ -69,7 +69,7 @@ -
+
+
@@ -167,6 +177,7 @@ import NetworkSelector from "./NetworkSelector.vue"; import Scan from "../Scan/Scan.vue"; import { GetExchangeRateResponse } from "../../../../pawket-chia-lib/models/api"; import BuyUSDS from "./BuyUSDS.vue"; +import SwapPage from "../Swap/SwapPage.vue"; import { isIos } from "../../../../pawket-chia-lib/services/util/platform"; @Component({ @@ -264,6 +275,9 @@ export default class AccountDetail extends Vue { case "/home/buy": this.buy(); break; + case "/home/swap": + this.swap(); + break; case "/home/errorLog": this.openErrorLog(); break; @@ -476,6 +490,20 @@ export default class AccountDetail extends Vue { }); } + swap(): void { + this.$buefy.modal.open({ + parent: this, + component: SwapPage, + trapFocus: true, + width: 700, + canCancel: ["outside", "escape"], + onCancel: () => this.handleModalClose("/home/swap"), + fullScreen: isMobile(), + props: { account: this.account }, + events: { close: () => this.handleModalClose("/home/swap") }, + }); + } + refresh(): void { store.dispatch("refreshBalance"); this.refreshRate(); diff --git a/packages/pawket/src/components/Swap/SimplifiedTokenAmountField.vue b/packages/pawket/src/components/Swap/SimplifiedTokenAmountField.vue new file mode 100644 index 00000000..459b8663 --- /dev/null +++ b/packages/pawket/src/components/Swap/SimplifiedTokenAmountField.vue @@ -0,0 +1,157 @@ + + + + + diff --git a/packages/pawket/src/components/Swap/SwapPage.vue b/packages/pawket/src/components/Swap/SwapPage.vue new file mode 100644 index 00000000..325524bc --- /dev/null +++ b/packages/pawket/src/components/Swap/SwapPage.vue @@ -0,0 +1,349 @@ + + + + diff --git a/packages/pawket/src/i18n/en.json b/packages/pawket/src/i18n/en.json index 8ffc4f52..f0ad3142 100644 --- a/packages/pawket/src/i18n/en.json +++ b/packages/pawket/src/i18n/en.json @@ -144,6 +144,7 @@ "button": { "receive": "Receive", "buy": "Buy", + "swap": "Swap", "send": "Send", "scan": "Scan", "confirm": "Confirm", diff --git a/packages/pawket/src/router/index.ts b/packages/pawket/src/router/index.ts index 7ebbd4b2..d6fdccea 100644 --- a/packages/pawket/src/router/index.ts +++ b/packages/pawket/src/router/index.ts @@ -53,6 +53,10 @@ const routes: Array = [ path: "buy", component: () => import(/* webpackChunkName: "home" */ "@/components/Cat/CatPanel.vue"), }, + { + path: "swap", + component: () => import(/* webpackChunkName: "home" */ "@/components/Cat/CatPanel.vue"), + }, { path: "scan", component: () => import(/* webpackChunkName: "home" */ "@/components/Cat/CatPanel.vue"), From 09e898d1d56f6f4449577ce658d774006250d955 Mon Sep 17 00:00:00 2001 From: LiangShuang Date: Tue, 18 Jul 2023 22:06:41 +0800 Subject: [PATCH 005/167] sign swap --- .../pawket-chia-lib/services/offer/summary.ts | 16 +- .../pawket/src/components/Swap/SwapPage.vue | 378 +++++++++++++----- 2 files changed, 286 insertions(+), 108 deletions(-) diff --git a/packages/pawket-chia-lib/services/offer/summary.ts b/packages/pawket-chia-lib/services/offer/summary.ts index 27fcaf62..5188abf7 100644 --- a/packages/pawket-chia-lib/services/offer/summary.ts +++ b/packages/pawket-chia-lib/services/offer/summary.ts @@ -165,17 +165,23 @@ function getRequestedCoins(bundle: UnsignedSpendBundle | SpendBundle): CoinSpend return bundle.coin_spends.filter(_ => _.coin.parent_coin_info == EmptyParent) } -export function getOfferEntities(ents: OfferTokenAmount[], target: Hex0x, catIds: { [name: string]: string }, symbol: string): OfferEntity[] { +export function getOfferEntities( + ents: OfferTokenAmount[], + target: Hex0x, + catIds: { [name: string]: string }, + xchSymbol: string, + amountIsMojoBased = false +): OfferEntity[] { return ents.map((_) => ({ - id: _.token == symbol ? "" : catIds[_.token], + id: _.token == xchSymbol ? "" : catIds[_.token], symbol: _.token, - amount: getAmount(_.token, _.amount, symbol), + amount: amountIsMojoBased ? BigInt(_.amount) : getAmount(_.token, _.amount, xchSymbol), target: target, })); } -function getAmount(symbol: string, amount: string, tokenSymbol: string): bigint { - const decimal = symbol == tokenSymbol ? 12 : 3; +function getAmount(symbol: string, amount: string, xchSymbol: string): bigint { + const decimal = symbol == xchSymbol ? 12 : 3; return BigInt(bigDecimal.multiply(amount, Math.pow(10, decimal))); } diff --git a/packages/pawket/src/components/Swap/SwapPage.vue b/packages/pawket/src/components/Swap/SwapPage.vue index 325524bc..47400887 100644 --- a/packages/pawket/src/components/Swap/SwapPage.vue +++ b/packages/pawket/src/components/Swap/SwapPage.vue @@ -3,87 +3,96 @@