-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: mf-6200 nft avatar decoration (#11598)
- Loading branch information
Showing
24 changed files
with
97 additions
and
109 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
import { useAsyncFn } from 'react-use' | ||
import { Web3Storage } from '@masknet/web3-providers' | ||
import type { AddressStorageV2 } from '@masknet/web3-providers/types' | ||
import { type NetworkPluginID, EnhanceableSite } from '@masknet/shared-base' | ||
import { NFT_AVATAR_DB_NAME } from '../constants.js' | ||
import { useCallback } from 'react' | ||
|
||
export function useSaveAddress() { | ||
return useAsyncFn(async (userId: string, pluginID: NetworkPluginID, account: string, network?: EnhanceableSite) => { | ||
const addressStorage = Web3Storage.createKVStorage( | ||
`${NFT_AVATAR_DB_NAME}_${network ?? EnhanceableSite.Twitter}`, | ||
) | ||
if (!addressStorage) return | ||
return useCallback( | ||
async (userId: string, pluginID: NetworkPluginID, account: string, network?: EnhanceableSite) => { | ||
const addressStorage = Web3Storage.createKVStorage( | ||
`${NFT_AVATAR_DB_NAME}_${network || EnhanceableSite.Twitter}`, | ||
) | ||
if (!addressStorage) return | ||
|
||
const prevData = (await addressStorage.get<AddressStorageV2>(userId).catch(() => ({}))) as | ||
| AddressStorageV2 | ||
| undefined | ||
const prevData = (await addressStorage.get<AddressStorageV2>(userId).catch(() => ({}))) as | ||
| AddressStorageV2 | ||
| undefined | ||
|
||
await addressStorage.set<AddressStorageV2>(userId, { | ||
...prevData, | ||
[pluginID]: account, | ||
[userId]: { address: account, networkPluginID: pluginID }, | ||
} as AddressStorageV2) | ||
}, []) | ||
await addressStorage.set<AddressStorageV2>(userId, { | ||
...prevData, | ||
[pluginID]: account, | ||
[userId]: { address: account, networkPluginID: pluginID }, | ||
} as AddressStorageV2) | ||
}, | ||
[], | ||
) | ||
} |
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
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.