Skip to content

Commit 7b1e64e

Browse files
authored
[core-v2.3.2-alpha.3 , react-v2.2.2-alpha.2, vue-v2.1.2-alpha.2]: Feature - copy address to clipboard (#1112)
* copy to clipboard * clipboard copy * clipboard copy * moved to utils * core package bump * refactor * refactor * refactor * package bump * package bump * remove unused
1 parent fba1270 commit 7b1e64e

File tree

7 files changed

+35
-9
lines changed

7 files changed

+35
-9
lines changed

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/core",
3-
"version": "2.4.0-alpha.2",
3+
"version": "2.4.0-alpha.3",
44
"repository": "blocknative/web3-onboard",
55
"scripts": {
66
"build": "rollup -c",

packages/core/src/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
"poweredBy": "powered by",
7171
"addAccount": "Add Account",
7272
"setPrimaryAccount": "Set Primary Account",
73-
"disconnectWallet": "Disconnect Wallet"
73+
"disconnectWallet": "Disconnect Wallet",
74+
"copyAddress": "Copy Wallet address"
7475
},
7576
"notify": {
7677
"transaction": {

packages/core/src/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ export function shortenEns(ens: string): string {
8383
return ens.length > 11 ? `${ens.slice(0, 4)}...${ens.slice(-6)}` : ens
8484
}
8585

86+
export async function copyWalletAddress(text: string): Promise<void> {
87+
try {
88+
const copy = await navigator.clipboard.writeText(text);
89+
return copy
90+
} catch (err) {
91+
console.error('Failed to copy: ', err)
92+
}
93+
}
94+
8695
export const chainIdToLabel: Record<string, string> = {
8796
'0x1': 'Ethereum',
8897
'0x3': 'Ropsten',

packages/core/src/views/account-center/WalletRow.svelte

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { fade } from 'svelte/transition'
44
import { ProviderRpcErrorCode } from '@web3-onboard/common'
55
import type { WalletState } from '../../types'
6-
import { shortenAddress, shortenEns } from '../../utils'
6+
import { shortenAddress, shortenEns, copyWalletAddress } from '../../utils'
77
import en from '../../i18n/en.json'
88
import SuccessStatusIcon from '../shared/SuccessStatusIcon.svelte'
99
import WalletAppBadge from '../shared/WalletAppBadge.svelte'
@@ -48,6 +48,14 @@
4848
}
4949
}
5050
}
51+
52+
function changeText() {
53+
en.accountCenter.copyAddress = 'Copied Successfully'
54+
setTimeout(hideMenu, 500)
55+
setTimeout(() => {
56+
en.accountCenter.copyAddress = 'Copy Wallet address'
57+
}, 700)
58+
}
5159
</script>
5260

5361
<style>
@@ -225,6 +233,15 @@
225233
default: en.accountCenter.disconnectWallet
226234
})}
227235
</li>
236+
<li
237+
on:click|stopPropagation={() => {
238+
copyWalletAddress(ens ? ens.name : address).then(() => {
239+
changeText()
240+
})
241+
}}
242+
>
243+
{en.accountCenter.copyAddress}
244+
</li>
228245
</ul>
229246
{/if}
230247
</div>

packages/demo/src/App.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@
213213
// }
214214
},
215215
position: 'topRight'
216-
},
217-
216+
}
218217
},
219218
// Sign up for your free api key at www.Blocknative.com
220219
apiKey: 'xxxxxx-bf21-42ec-a093-9d37e426xxxx'

packages/react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/react",
3-
"version": "2.2.2",
3+
"version": "2.2.3-alpha.1",
44
"description": "Collection of React Hooks for web3-onboard",
55
"repository": "blocknative/web3-onboard",
66
"module": "dist/index.js",
@@ -24,7 +24,7 @@
2424
"typescript": "^4.5.5"
2525
},
2626
"dependencies": {
27-
"@web3-onboard/core": "^2.3.2",
27+
"@web3-onboard/core": "^2.4.0-alpha.3",
2828
"@web3-onboard/common": "^2.1.4",
2929
"use-sync-external-store": "1.0.0"
3030
},

packages/vue/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/vue",
3-
"version": "2.1.2",
3+
"version": "2.1.3-alpha.1",
44
"description": "Vue Composable for web3-onboard",
55
"repository": "blocknative/web3-onboard",
66
"module": "dist/index.js",
@@ -25,7 +25,7 @@
2525
"@vueuse/core": "^8.4.2",
2626
"@vueuse/rxjs": "^8.2.0",
2727
"@web3-onboard/common": "^2.1.4",
28-
"@web3-onboard/core": "^2.3.2",
28+
"@web3-onboard/core": "^2.4.0-alpha.3",
2929
"vue-demi": "^0.12.4"
3030
},
3131
"peerDependencies": {

0 commit comments

Comments
 (0)