-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c33ac8
commit 9da373b
Showing
27 changed files
with
1,017 additions
and
124 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @ts-check | ||
|
||
const { extendEslint } = require("@graz-sh/style-guide"); | ||
|
||
module.exports = extendEslint(["browser-node", "react", "typescript", "tsup"], { | ||
ignorePatterns: ["dist/**"], | ||
root: true, | ||
}); |
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,4 @@ | ||
/chains/* | ||
/dist/**/* | ||
!/chains/*.stub | ||
!/dist/**/.gitkeep |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Graz | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,9 @@ | ||
# graz-adapter-station | ||
|
||
[![npm/v](https://badgen.net/npm/v/graz-adapter-station)](https://www.npmjs.com/package/graz-adapter-station) | ||
[![npm/dt](https://badgen.net/npm/dt/graz-adapter-station)](https://www.npmjs.com/package/graz-adapter-station) | ||
[![stars](https://badgen.net/github/stars/graz-sh/graz)](https://github.com/graz-sh/graz) | ||
|
||
React hooks for Cosmos. Learn more about graz on the [official GitHub repository](https://github.com/graz-sh/graz). | ||
|
||
[MIT License, Copyright (c) 2023 Graz](./LICENSE) |
Empty file.
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,6 @@ | ||
import Station from "@terra-money/station-connector"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
declare interface Window { | ||
station?: Station; | ||
} |
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,39 @@ | ||
{ | ||
"name": "graz-adapter-station", | ||
"description": "Graz adapter for Station Wallet", | ||
"version": "0.0.2", | ||
"repository": "https://github.com/graz-sh/graz.git", | ||
"homepage": "https://github.com/graz-sh/graz", | ||
"bugs": "https://github.com/graz-sh/graz/issues", | ||
"files": [ | ||
"dist/*.d.ts", | ||
"dist/*.js", | ||
"dist/*.mjs" | ||
], | ||
"sideEffects": false, | ||
"scripts": { | ||
"build": "tsup", | ||
"dev": "tsup --watch", | ||
"lint": "eslint --fix \"src/**/*.{ts,tsx}\"", | ||
"prepublishOnly": "pnpm build" | ||
}, | ||
"peerDependencies": { | ||
"graz": ">=0.0.37" | ||
}, | ||
"devDependencies": { | ||
"graz": "*", | ||
"typescript": "^5.2.2" | ||
}, | ||
"keywords": [ | ||
"graz", | ||
"graz-adapter", | ||
"graz-adapter-station", | ||
"station-wallet", | ||
"station", | ||
"use-station" | ||
], | ||
"license": "MIT", | ||
"dependencies": { | ||
"@terra-money/station-connector": "^1.0.15" | ||
} | ||
} |
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,149 @@ | ||
import type { ChainInfo } from "@keplr-wallet/types"; | ||
import type { AccountData, GrazAdapter } from "graz"; | ||
import { SignDoc } from "cosmjs-types/cosmos/tx/v1beta1/tx"; | ||
import { DirectSignResponse } from "@cosmjs/proto-signing"; | ||
import { ChainInfoResponse } from "@terra-money/station-connector/keplrConnector"; | ||
|
||
export class StationAdapter implements GrazAdapter { | ||
name = "Station"; | ||
id = "station"; | ||
keystoreEvent = "station_wallet_change"; | ||
|
||
private getConnector() { | ||
if (typeof window.station !== "undefined") return window.station.keplr; | ||
throw new Error("window.keplr is not defined"); | ||
} | ||
|
||
checkConnector() { | ||
try { | ||
this.getConnector(); | ||
return true; | ||
} catch (error) { | ||
console.error(error); | ||
return false; | ||
} | ||
} | ||
|
||
async enable(chainId: string) { | ||
try { | ||
const isAvailable = this.checkConnector(); | ||
if (!isAvailable) { | ||
throw new Error("Station is not available"); | ||
} | ||
await this.getConnector().enable(chainId); | ||
} catch (error) { | ||
console.error(error); | ||
throw error; | ||
} | ||
} | ||
|
||
async experimentalSuggestChain(chainInfo: ChainInfo) { | ||
try { | ||
const isAvailable = this.checkConnector(); | ||
if (!isAvailable) { | ||
throw new Error("Station is not available"); | ||
} | ||
|
||
const chainInfoResponse: ChainInfoResponse = Object.assign(chainInfo, { | ||
chainSymbolImageUrl: chainInfo.chainSymbolImageUrl || "", | ||
stakeCurrency: { | ||
coinDecimals: chainInfo.stakeCurrency.coinDecimals, | ||
coinDenom: chainInfo.stakeCurrency.coinDenom, | ||
coinImageUrl: chainInfo.stakeCurrency.coinImageUrl || "", | ||
coinMinimalDenom: chainInfo.stakeCurrency.coinMinimalDenom, | ||
}, | ||
currencies: chainInfo.currencies.map((currency) => ({ | ||
coinDecimals: currency.coinDecimals, | ||
coinDenom: currency.coinDenom, | ||
coinImageUrl: currency.coinImageUrl || "", | ||
coinMinimalDenom: currency.coinMinimalDenom, | ||
})), | ||
feeCurrencies: chainInfo.feeCurrencies.map((currency) => ({ | ||
coinDecimals: currency.coinDecimals, | ||
coinDenom: currency.coinDenom, | ||
coinImageUrl: currency.coinImageUrl || "", | ||
coinMinimalDenom: currency.coinMinimalDenom, | ||
gasPriceStep: { | ||
average: currency.gasPriceStep?.average || 0, | ||
high: currency.gasPriceStep?.high || 0, | ||
low: currency.gasPriceStep?.low || 0, | ||
}, | ||
})), | ||
}); | ||
|
||
await this.getConnector().experimentalSuggestChain(chainInfoResponse); | ||
} catch (error) { | ||
console.error(error); | ||
throw error; | ||
} | ||
} | ||
|
||
async getAccount(chainId: string, prefix?: string): Promise<AccountData> { | ||
try { | ||
const isAvailable = this.checkConnector(); | ||
if (!isAvailable) { | ||
throw new Error("Station is not available"); | ||
} | ||
const key = await this.getConnector().getKey(chainId); | ||
return { | ||
address: key.address, | ||
bech32Address: key.bech32Address, | ||
pubKey: key.pubKey, | ||
algo: key.algo, | ||
}; | ||
} catch (error) { | ||
console.error(error); | ||
throw error; | ||
} | ||
} | ||
|
||
getOfflineSigner(chainId: string) { | ||
try { | ||
const isAvailable = this.checkConnector(); | ||
if (!isAvailable) { | ||
throw new Error("Station is not available"); | ||
} | ||
const signerOnlyAmino = this.getConnector().getOfflineSignerOnlyAmino(chainId); | ||
const signDirect: (signerAddress: string, signDoc: SignDoc) => Promise<DirectSignResponse> = async ( | ||
signerAddress: string, | ||
signDoc: SignDoc, | ||
) => { | ||
throw new Error("signDirect not supported by Station"); | ||
}; | ||
const signer = Object.assign(signerOnlyAmino, { signDirect }); | ||
|
||
return signer; | ||
} catch (error) { | ||
console.error(error); | ||
throw error; | ||
} | ||
} | ||
|
||
getOfflineSignerOnlyAmino(chainId: string) { | ||
try { | ||
const isAvailable = this.checkConnector(); | ||
if (!isAvailable) { | ||
throw new Error("Station is not available"); | ||
} | ||
const signer = this.getConnector().getOfflineSignerOnlyAmino(chainId); | ||
return signer; | ||
} catch (error) { | ||
console.error(error); | ||
throw error; | ||
} | ||
} | ||
|
||
async getOfflineSignerAuto(chainId: string) { | ||
try { | ||
const isAvailable = this.checkConnector(); | ||
if (!isAvailable) { | ||
throw new Error("Station is not available"); | ||
} | ||
const signer = await this.getConnector().getOfflineSignerAuto(chainId); | ||
return signer; | ||
} catch (error) { | ||
console.error(error); | ||
throw error; | ||
} | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"extends": "@graz-sh/style-guide/tsconfig.json", | ||
"compilerOptions": { | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true | ||
}, | ||
"exclude": ["node_modules"], | ||
"include": ["env.d.ts", "**/*.ts", "**/*.tsx"] | ||
} |
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 { defineConfig } from "tsup"; | ||
|
||
export default defineConfig(({ watch }) => ({ | ||
cjsInterop: true, | ||
clean: !watch, | ||
dts: true, | ||
entry: ["src/*.ts"], | ||
format: ["cjs", "esm"], | ||
minify: !watch, | ||
shims: true, | ||
splitting: true, | ||
treeshake: true, | ||
})); |
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
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
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.