-
Notifications
You must be signed in to change notification settings - Fork 6
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
56bae51
commit dfe347f
Showing
9 changed files
with
197 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
name: Playwright Tests | ||
on: | ||
push: | ||
branches: [ main, master ] | ||
branches: | ||
- main | ||
pull_request: | ||
branches: [ main, master ] | ||
branches: | ||
- main | ||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Install Playwright Browsers | ||
run: npx playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: npx playwright test | ||
- uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts/* | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Install Playwright Browsers | ||
run: npx playwright install --with-deps | ||
- name: Run Playwright tests | ||
run: npx playwright test | ||
- uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 | ||
- name: Bump version and publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: | | ||
npm run build | ||
npm run publish |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,79 @@ | ||
import { | ||
LocalAccount, | ||
Hex, | ||
Transport, | ||
createWalletClient, | ||
fromHex, | ||
} from "viem"; | ||
import * as chains from "viem/chains"; | ||
|
||
export type Wallet = ReturnType<typeof createWallet>; | ||
|
||
export function createWallet(account: LocalAccount, transport: Transport) { | ||
let chainId: string | undefined; | ||
|
||
return { | ||
request: async ({ | ||
method, | ||
params, | ||
}: { | ||
method: string; | ||
params?: Array<unknown>; | ||
}) => { | ||
try { | ||
const client = createWalletClient({ | ||
account, | ||
chain: getChain(chainId), | ||
transport, | ||
}); | ||
|
||
if (method === "eth_accounts" || method === "eth_requestAccounts") { | ||
return client.getAddresses(); | ||
} | ||
|
||
if ( | ||
method === "wallet_requestPermissions" || | ||
method === "wallet_revokePermissions" | ||
) { | ||
return [{ parentCapability: "eth_accounts" }]; | ||
} | ||
|
||
if (method === "wallet_switchEthereumChain") { | ||
chainId = (params?.[0] as any).chainId; | ||
return null; | ||
} | ||
|
||
if (method === "personal_sign") { | ||
return client.account.signMessage({ | ||
message: { | ||
raw: params?.[0] as Hex, | ||
}, | ||
}); | ||
} | ||
|
||
return await client.request({ | ||
method: method as any, | ||
params: params as any, | ||
}); | ||
} catch (error) { | ||
console.error("error", error); | ||
return null; | ||
} | ||
}, | ||
}; | ||
} | ||
|
||
function getChain(chainIdHex: string | undefined) { | ||
if (!chainIdHex) return chains.mainnet; | ||
|
||
const chainId = fromHex(chainIdHex as Hex, "number"); | ||
for (const chain of Object.values(chains)) { | ||
if ("id" in chain) { | ||
if (chain.id === chainId) { | ||
return chain; | ||
} | ||
} | ||
} | ||
|
||
return chains.mainnet; | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from "./playwright"; | ||
export * from "./privateKeyWalletRequest"; | ||
export * from "./installMockWallet"; | ||
export * from "./createWallet"; |
Oops, something went wrong.